File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson13 ;
2
+ import java .util .HashMap ;
3
+ import java .util .Map ;
2
4
3
5
public class Lesson13 {
4
6
@@ -7,6 +9,17 @@ public class Lesson13 {
7
9
* https://leetcode.com/problems/permutation-difference-between-two-strings
8
10
*/
9
11
public int findPermutationDifference (String s , String t ) {
10
- return 0 ;
12
+ Map <Character , Integer > indexMap = new HashMap <>();
13
+ for (int i = 0 ; i < s .length (); i ++) {
14
+ indexMap .put (s .charAt (i ), i );
15
+ }
16
+
17
+ int permutationDifference = 0 ;
18
+ for (int i = 0 ; i < t .length (); i ++) {
19
+ char ch = t .charAt (i );
20
+ int indexInS = indexMap .get (ch );
21
+ permutationDifference += Math .abs (indexInS - i );
22
+ }
23
+ return permutationDifference ;
11
24
}
12
25
}
You can’t perform that action at this time.
0 commit comments