Skip to content

Commit 0192e12

Browse files
author
“A1-4U2T1NN”
committed
feat: imported Java Permutation Difference Calculator and converted into TypeScrpit;
1 parent f5872dd commit 0192e12

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lesson_13/maps_ts/src/lesson13.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,16 @@
33
* https://leetcode.com/problems/permutation-difference-between-two-strings
44
*/
55
export function findPermutationDifference(s: string, t: string): number {
6-
return 0;
7-
}
6+
let permuDifference = 0;
7+
// Created a counter to track Permutation Difference
8+
for (let i = 0; i < s.length; i++) {
9+
// Loops through each letter in string 's'
10+
const difference = s.indexOf(s.charAt(i)) - t.indexOf(s.charAt(i));
11+
// Subtracts possitional value of string 't' from the possitional value of string 's'
12+
permuDifference += Math.abs(difference);
13+
// Converts difference into absolute value and adds it to the Permutation Difference
14+
}
15+
return permuDifference;
16+
// Returns the total Permutation Difference value
17+
}
18+

0 commit comments

Comments
 (0)