File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson13 ;
2
2
3
+ import java .util .HashMap ;
4
+
3
5
public class Lesson13 {
4
6
5
7
/**
6
8
* Provide the solution to LeetCode 3146 here:
7
9
* https://leetcode.com/problems/permutation-difference-between-two-strings
8
10
*/
11
+
9
12
public int findPermutationDifference (String s , String t ) {
10
- return 0 ;
13
+
14
+ //var charLocation = new HashMap<Character, Integer>();
15
+
16
+ HashMap <Character ,Integer > map = new HashMap ();
17
+ int sum =0 ;
18
+ for (int i =0 ; i < s .length (); i ++) {
19
+ map .putIfAbsent (s .charAt (i ),i );
20
+ }
21
+ for (char key : map .keySet ()) {
22
+ int indexInt = t .indexOf (Character .toString (key ));
23
+ sum += Math .abs (s .indexOf (key )- indexInt );
24
+ }
25
+ return sum ;
11
26
}
12
27
}
You can’t perform that action at this time.
0 commit comments