Skip to content

Commit afa447b

Browse files
committed
Feat: adds Shawn Dunsmore Jr Lesson 13 indexfinder.
1 parent 43b0c16 commit afa447b

File tree

1 file changed

+21
-3
lines changed
  • lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13

1 file changed

+21
-3
lines changed
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.codedifferently.lesson13;
2+
import java.util.HashMap;
23

34
public class Lesson13 {
45

@@ -7,6 +8,23 @@ public class Lesson13 {
78
* https://leetcode.com/problems/permutation-difference-between-two-strings
89
*/
910
public int findPermutationDifference(String s, String t) {
10-
return 0;
11-
}
12-
}
11+
12+
HashMap<Character, Integer> indexFinder = new HashMap<>();
13+
14+
15+
for (int i = 0; i < s.length(); i++) {
16+
char character = s.charAt(i);
17+
indexFinder.put(character, i);
18+
}
19+
20+
int sum = 0;
21+
22+
for (int i = 0; i < t.length(); i++) {
23+
char character = t.charAt(i);
24+
int value = indexFinder.get(character);
25+
sum += Math.abs(value - i);
26+
}
27+
28+
return sum;
29+
}
30+
}

0 commit comments

Comments
 (0)