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