Skip to content

Commit a551f55

Browse files
committed
feat:add lesson 13
1 parent bf96654 commit a551f55

File tree

1 file changed

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

1 file changed

+15
-1
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package com.codedifferently.lesson13;
22

3+
import java.util.HashMap;
4+
35
public class Lesson13 {
46

57
/**
68
* Provide the solution to LeetCode 3146 here:
79
* https://leetcode.com/problems/permutation-difference-between-two-strings
810
*/
911
public int findPermutationDifference(String s, String t) {
10-
return 0;
12+
HashMap<Character, Integer> indexMap = new HashMap<>();
13+
for (int i = 0; i < s.length(); i++) {
14+
indexMap.put(s.charAt(i), i);
15+
}
16+
int difference = 0;
17+
for (int i = 0; i < t.length(); i++) {
18+
if (indexMap.containsKey(t.charAt(i))) {
19+
difference += Math.abs(indexMap.get(t.charAt(i)) - i);
20+
}
21+
}
22+
return difference;
1123
}
1224
}
25+
// Used ChatGPT to explain code.
26+

0 commit comments

Comments
 (0)