Skip to content

Commit 71539be

Browse files
committed
feat: Adds Zion's LeetCode PermutationDifference method to Lesson_13 hw
1 parent 32f5984 commit 71539be

File tree

1 file changed

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

1 file changed

+12
-1
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
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+
var charLocation = new HashMap<Character, Integer>();
13+
int charSum = 0;
14+
for (int i = 0; i < s.length(); i++) {
15+
charLocation.put(s.charAt(i), i);
16+
}
17+
for (int i = 0; i < t.length(); i++) {
18+
int charResult = charLocation.get(t.charAt(i));
19+
charSum += Math.abs(charResult - i);
20+
}
21+
return charSum;
1122
}
1223
}

0 commit comments

Comments
 (0)