File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
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
- return 0 ;
7
- }
6
+ const letters = new Map < string , number > ( ) ;
7
+ for ( let i = 0 ; i < s . length ; i ++ ) {
8
+ letters . set ( s . charAt ( i ) , i ) ;
9
+ }
10
+ let permDifferences = 0 ;
11
+ for ( const key of letters . keys ( ) ) {
12
+ const indexInT = t . indexOf ( String ( key ) ) ;
13
+ permDifferences += Math . abs ( s . indexOf ( key ) - indexInT ) ;
14
+ }
15
+ // int sumDifference = 0;
16
+ // for (int i = 0; i < s.length(); i++) {
17
+ // char currentChar = s.charAt(i);
18
+ // int indexInT = t.indexOf(currentChar);
19
+ // int difference = Math.abs(i - indexInT);
20
+ // sumDifference += difference;
21
+
22
+ return permDifferences ;
23
+ }
24
+
You can’t perform that action at this time.
0 commit comments