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 e95e3eaCopy full SHA for e95e3ea
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13/Lesson13.java
@@ -1,12 +1,26 @@
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> map = new HashMap<>();
13
14
+ for(int i = 0; i<t.length(); i++){
15
+ map.put(t.charAt(i), i);
16
+ }
17
18
+ int difference = 0;
19
+ for(int i = 0; i<s.length(); i++) {
20
+ int idx = map.get(s.charAt(i));
21
+ difference += Math.abs(i - idx);
22
23
24
+ return difference;
25
}
26
0 commit comments