Skip to content

Commit 4049501

Browse files
committed
feat: lesson_13 solution implementation by Tommy Tran
1 parent 39c8f59 commit 4049501

File tree

1 file changed

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

1 file changed

+17
-1
lines changed
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
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> smap = new HashMap<>();
13+
HashMap<Character,Integer> tmap = new HashMap<>();
14+
int sum = 0;
15+
for (int i =0; i <s.length(); i++){
16+
smap.put(s.charAt(i),i);
17+
tmap.put(t.charAt(i),i);
18+
}
19+
for (Character key:smap.keySet()){
20+
if (tmap.containsKey(key)) {
21+
Integer val1 = smap.get(key);
22+
Integer val2 = tmap.get(key);
23+
sum += Math.abs(val1-val2);
24+
}
25+
}
26+
return sum;
1127
}
1228
}

0 commit comments

Comments
 (0)