We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent abb394d commit 16fc235Copy full SHA for 16fc235
lesson_13/maps_ts/src/lesson13.ts
@@ -1,7 +1,20 @@
1
-/**
2
- * Provide the solution to LeetCode 3146 here:
3
- * https://leetcode.com/problems/permutation-difference-between-two-strings
4
- */
5
export function findPermutationDifference(s: string, t: string): number {
6
- return 0;
+ const tIndexMap = new Map<string, number>();
+
+ for (let i = 0; i < t.length; i++) {
+ tIndexMap.set(t[i], i);
+ }
7
8
+ let totalDifference = 0;
9
10
+ for (let i = 0; i < s.length; i++) {
11
+ const c = s[i];
12
+ const indexInT = tIndexMap.get(c);
13
14
+ if (indexInT !== undefined) {
15
+ totalDifference += Math.abs(i - indexInT);
16
17
18
19
+ return totalDifference;
20
}
0 commit comments