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