Skip to content

Commit 83c7a80

Browse files
committed
feat: adds Zion's PermutationDifference method in lesson_13.ts extra credit hw
1 parent 71539be commit 83c7a80

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 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));
13+
charSum += Math.abs(charResult - i);
14+
}
15+
return charSum;
16+
717
}

0 commit comments

Comments
 (0)