Skip to content

Commit c84cbd4

Browse files
committed
feat: LeetCode 3145 Typescript by Dwight Blue
1 parent 4ad13ed commit c84cbd4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lesson_13/maps_ts/src/lesson13.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@
33
* https://leetcode.com/problems/permutation-difference-between-two-strings
44
*/
55
export function findPermutationDifference(s: string, t: string): number {
6-
return 0;
6+
let sum = 0;
7+
const strStone = new Map<string, number>();
8+
9+
for (let i = 0; i < s.length; i++) {
10+
strStone.set(s.charAt(i),i);
11+
}
12+
for (const key of strStone.keys()) {
13+
const indexSTR = t.indexOf(key);
14+
sum += Math.abs(s.indexOf(key) - indexSTR);
15+
}
16+
return sum;
717
}

0 commit comments

Comments
 (0)