We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 39c8f59 commit 7395e13Copy full SHA for 7395e13
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13/Lesson13.java
@@ -1,12 +1,23 @@
1
package com.codedifferently.lesson13;
2
3
+import java.util.HashMap;
4
+
5
public class Lesson13 {
6
7
/**
8
* Provide the solution to LeetCode 3146 here:
9
* https://leetcode.com/problems/permutation-difference-between-two-strings
10
*/
11
public int findPermutationDifference(String s, String t) {
- 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;
22
}
23
0 commit comments