File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ package com .codedifferently .lesson13 ;
2+
3+ public class Char {}
Original file line number Diff line number Diff line change 11package com .codedifferently .lesson13 ;
22
3+ import java .util .HashMap ;
4+
35public class Lesson13 {
46
57 /**
68 * Provide the solution to LeetCode 3146 here:
79 * https://leetcode.com/problems/permutation-difference-between-two-strings
810 */
911 public int findPermutationDifference (String s , String t ) {
10- return 0 ;
12+ var charCountS = new HashMap <Character , Integer >();
13+
14+ int totalDifference = 0 ;
15+
16+ for (int sIndex = 0 ; sIndex < s .length (); sIndex ++) {
17+ charCountS .put (s .charAt (sIndex ), sIndex );
18+ }
19+ for (int tIndex = 0 ; tIndex < t .length (); tIndex ++) {
20+ int countIndexS = charCountS .put (t .charAt (tIndex ), tIndex );
21+
22+ totalDifference += Math .abs (countIndexS - tIndex );
23+ }
24+ return totalDifference ;
1125 }
1226}
You can’t perform that action at this time.
0 commit comments