Skip to content

Commit 5629699

Browse files
author
jjcapparell
committed
Feat: added content to Lesson13.java
1 parent 32f5984 commit 5629699

File tree

1 file changed

+24
-6
lines changed
  • lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13

1 file changed

+24
-6
lines changed
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
package com.codedifferently.lesson13;
2-
2+
import java.util.HashMap;
33
public class Lesson13 {
44

5-
/**
6-
* Provide the solution to LeetCode 3146 here:
7-
* https://leetcode.com/problems/permutation-difference-between-two-strings
8-
*/
95
public int findPermutationDifference(String s, String t) {
10-
return 0;
6+
HashMap<Character, Integer> stringS = new HashMap<>();
7+
for (int i=0; i<s.length(); i++){
8+
stringS.put(s.charAt(i), i);
9+
}
10+
HashMap<Character, Integer> stringT = new HashMap<>();
11+
for (int i=0; i<t.length(); i++){
12+
stringT.put(t.charAt(i), i);
13+
}
14+
return compareMaps(stringS, stringT);
15+
16+
}
17+
18+
public int compareMaps(HashMap<Character, Integer> map1, HashMap<Character, Integer> map2) {
19+
int diffSum=0;
20+
for (Character key : map1.keySet()) {
21+
if (map2.containsKey(key)) {
22+
int value1 = map1.get(key);
23+
int value2 = map2.get(key);
24+
int difference = Math.abs(value1 - value2);
25+
diffSum+=difference;
26+
}
27+
}
28+
return diffSum;
1129
}
1230
}

0 commit comments

Comments
 (0)