Skip to content

Commit

Permalink
feat: implemented LeetCode 3146 using a map
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierCruz5106 committed Oct 23, 2024
1 parent 39c8f59 commit f167f6f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lesson_13/maps_ts/src/lesson13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,17 @@
* https://leetcode.com/problems/permutation-difference-between-two-strings
*/
export function findPermutationDifference(s: string, t: string): number {
return 0;
const map = new Map<string, number>();

for (let i = 0; i < t.length; i++) {
map.set(t[i], i);
}

let difference = 0;
for (let i = 0; i < s.length; i++) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
difference += Math.abs(i - map.get(s[i])!);
}

return difference;
}

0 comments on commit f167f6f

Please sign in to comment.