Skip to content

Commit 40355ed

Browse files
fix lesson_13
1 parent 16fc235 commit 40355ed

File tree

1 file changed

+19
-5
lines changed
  • lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13

1 file changed

+19
-5
lines changed
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package com.codedifferently.lesson13;
22

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

5-
/**
6-
* Provide the solution to LeetCode 3146 here:
7-
* https://leetcode.com/problems/permutation-difference-between-two-strings
8-
*/
8+
99
public int findPermutationDifference(String s, String t) {
10-
return 0;
10+
11+
Map<Character, Integer> sIndexMap = new HashMap<>();
12+
for (int i = 0; i < s.length(); i++) {
13+
sIndexMap.put(s.charAt(i), i);
14+
}
15+
16+
int totalDifference = 0;
17+
18+
for (int i = 0; i < t.length(); i++) {
19+
char currentChar = t.charAt(i);
20+
int indexInS = sIndexMap.get(currentChar);
21+
totalDifference += Math.abs(indexInS - i);
22+
}
23+
24+
return totalDifference;
1125
}
1226
}

0 commit comments

Comments
 (0)