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