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