Skip to content

Commit 7395e13

Browse files
author
Yafiaha
committed
Feat: Lesson-13 PermutationDifference LeetCode
1 parent 39c8f59 commit 7395e13

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+
HashMap<Character, Integer> hashMap = new HashMap<>();
13+
int pD = 0;
14+
for (int i = 0; i < s.length(); i++) {
15+
hashMap.put(s.charAt(i), i);
16+
}
17+
for (char key : hashMap.keySet()) {
18+
int indexT = t.indexOf(Character.toString(key));
19+
pD += Math.abs(s.indexOf(key) - indexT);
20+
}
21+
return pD;
1122
}
1223
}

0 commit comments

Comments
 (0)