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 71539be commit 83c7a80Copy full SHA for 83c7a80
lesson_13/maps_ts/src/lesson13.ts
@@ -3,5 +3,15 @@
3
* https://leetcode.com/problems/permutation-difference-between-two-strings
4
*/
5
export function findPermutationDifference(s: string, t: string): number {
6
- return 0;
+ 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
+
17
}
0 commit comments