File tree Expand file tree Collapse file tree 1 file changed +6
-14
lines changed
Expand file tree Collapse file tree 1 file changed +6
-14
lines changed Original file line number Diff line number Diff line change 11export function findPermutationDifference ( s : string , t : string ) : number {
22 const stringS = new Map < string , number > ( ) ;
3- for ( let i = 0 ; i < s . length ; i ++ ) {
4- stringS . set ( s . charAt ( i ) , i ) ;
5- }
6-
73 const stringT = new Map < string , number > ( ) ;
4+ let diffSum = 0 ;
85 for ( let i = 0 ; i < t . length ; i ++ ) {
6+ stringS . set ( s . charAt ( i ) , i ) ;
97 stringT . set ( t . charAt ( i ) , i ) ;
108 }
11-
12- return compareMaps ( stringS , stringT ) ;
13- }
14-
15- function compareMaps ( map1 : Map < string , number > , map2 : Map < string , number > ) : number {
16- let diffSum = 0 ;
17- for ( const key of map1 . keys ( ) ) {
18- if ( map2 . has ( key ) ) {
9+ for ( const key of stringS . keys ( ) ) {
10+ if ( stringT . has ( key ) ) {
1911 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20- const value1 = map1 . get ( key ) ! ; // Non-null assertion because we checked with has()
12+ const value1 = stringS . get ( key ) ! ; // Non-null assertion because we checked with has()
2113 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22- const value2 = map2 . get ( key ) ! ; // Non-null assertion
14+ const value2 = stringT . get ( key ) ! ; // Non-null assertion
2315 const difference = Math . abs ( value1 - value2 ) ;
2416 diffSum += difference ;
2517 }
You can’t perform that action at this time.
0 commit comments