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 39c8f59 commit f167f6fCopy full SHA for f167f6f
lesson_13/maps_ts/src/lesson13.ts
@@ -3,5 +3,17 @@
3
* https://leetcode.com/problems/permutation-difference-between-two-strings
4
*/
5
export function findPermutationDifference(s: string, t: string): number {
6
- return 0;
+ const map = new Map<string, number>();
7
+
8
+ for (let i = 0; i < t.length; i++) {
9
+ map.set(t[i], i);
10
+ }
11
12
+ let difference = 0;
13
+ for (let i = 0; i < s.length; i++) {
14
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15
+ difference += Math.abs(i - map.get(s[i])!);
16
17
18
+ return difference;
19
}
0 commit comments