Skip to content

Commit 8b9f40a

Browse files
committed
feat: Adds Nana's Lesson13.java homework
1 parent bf96654 commit 8b9f40a

File tree

1 file changed

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

1 file changed

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

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
36
public class Lesson13 {
47

58
/**
69
* Provide the solution to LeetCode 3146 here:
710
* https://leetcode.com/problems/permutation-difference-between-two-strings
811
*/
912
public int findPermutationDifference(String s, String t) {
10-
return 0;
13+
Map<Character, Integer> smap = new HashMap<>();
14+
for (int i = 0; i < s.length(); i++) {
15+
char c = s.charAt(i);
16+
smap.put(c, i);
17+
}
18+
Map<Character, Integer> tmap = new HashMap<>();
19+
for (int i = 0; i < t.length(); i++) {
20+
char c = t.charAt(i);
21+
tmap.put(c, i);
22+
}
23+
int ans = 0;
24+
for (char c : smap.keySet()) {
25+
ans = ans + Math.abs(smap.get(c) - tmap.get(c));
26+
}
27+
return ans;
1128
}
1229
}

0 commit comments

Comments
 (0)