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 4ad13ed commit c84cbd4Copy full SHA for c84cbd4
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 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;
17
}
0 commit comments