Skip to content

Commit ef98f71

Browse files
committed
feat: lesson_13 leet code solution in ts
1 parent 017835b commit ef98f71

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lesson_13/maps_ts/src/lesson13.ts

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

0 commit comments

Comments
 (0)