File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 3
3
* https://leetcode.com/problems/permutation-difference-between-two-strings
4
4
*/
5
5
export function findPermutationDifference ( s : string , t : string ) : number {
6
- let charLocation = new Map < string , number > ( ) ;
7
- let charSum = 0 ;
8
- for ( let i = 0 ; i < s . length ; i ++ ) {
9
- charLocation . set ( s [ i ] , i ) ;
10
- }
11
- for ( let i = 0 ; i < t . length ; i ++ ) {
12
- let charResult = charLocation . get ( t . charAt ( i ) ) ;
6
+ const charLocation = new Map < string , number > ( ) ;
7
+ let charSum = 0 ;
8
+ for ( let i = 0 ; i < s . length ; i ++ ) {
9
+ charLocation . set ( s [ i ] , i ) ;
10
+ }
11
+ for ( let i = 0 ; i < t . length ; i ++ ) {
12
+ const charResult = charLocation . get ( t . charAt ( i ) ) ;
13
+ if ( charResult !== undefined ) {
13
14
charSum += Math . abs ( charResult - i ) ;
14
15
}
15
- return charSum ;
16
-
16
+ }
17
+ return charSum ;
17
18
}
You can’t perform that action at this time.
0 commit comments