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