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 11package com .codedifferently .lesson13 ;
22
3+ import java .util .HashMap ;
4+ import java .util .Map ;
5+
36public class Lesson13 {
47
58 /**
69 * Provide the solution to LeetCode 3146 here:
710 * https://leetcode.com/problems/permutation-difference-between-two-strings
811 */
912 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 ;
1128 }
1229}
You can’t perform that action at this time.
0 commit comments