Skip to content

Commit be2fa72

Browse files
committed
feat: added Lesson_13 solution for Chelsea
1 parent 32f5984 commit be2fa72

File tree

1 file changed

+14
-1
lines changed
  • lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13

1 file changed

+14
-1
lines changed
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
package com.codedifferently.lesson13;
2+
import java.util.HashMap;
3+
import java.util.Map;
24

35
public class Lesson13 {
46

@@ -7,6 +9,17 @@ public class Lesson13 {
79
* https://leetcode.com/problems/permutation-difference-between-two-strings
810
*/
911
public int findPermutationDifference(String s, String t) {
10-
return 0;
12+
Map<Character, Integer> indexMap = new HashMap<>();
13+
for (int i = 0; i < s.length(); i++) {
14+
indexMap.put(s.charAt(i), i);
15+
}
16+
17+
int permutationDifference = 0;
18+
for (int i = 0; i < t.length(); i++) {
19+
char ch = t.charAt(i);
20+
int indexInS = indexMap.get(ch);
21+
permutationDifference += Math.abs(indexInS - i);
22+
}
23+
return permutationDifference;
1124
}
1225
}

0 commit comments

Comments
 (0)