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 11package com .codedifferently .lesson13 ;
2+ import java .util .HashMap ;
3+ import java .util .Map ;
24
35public class Lesson13 {
46
@@ -7,6 +9,17 @@ public class Lesson13 {
79 * https://leetcode.com/problems/permutation-difference-between-two-strings
810 */
911 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 ;
1124 }
1225}
You can’t perform that action at this time.
0 commit comments