File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change 11package com .codedifferently .lesson13 ;
22
3- public class Lesson13 {
3+ import java . util . HashMap ;
44
5- /**
6- * Provide the solution to LeetCode 3146 here:
7- * https://leetcode.com/problems/permutation-difference-between-two-strings
8- */
5+ public class Lesson13 {
96 public int findPermutationDifference (String s , String t ) {
10-
11- int sumDifference = 0 ;
7+ HashMap < Character , Integer > letters = new HashMap <>();
8+ int permDifferences = 0 ;
129 for (int i = 0 ; i < s .length (); i ++) {
13- char currentChar = s .charAt (i );
14- int indexInT = t .indexOf (currentChar );
15- int difference = Math .abs (i - indexInT );
16- sumDifference += difference ;
10+ letters .put (s .charAt (i ), i );
1711 }
18- System .out .println ("Here is the Permutation Difference is: + letters.get" );
19- return sumDifference ;
12+ for (char key : letters .keySet ()) {
13+ int indexInT = t .indexOf (Character .toString (key ));
14+ permDifferences += Math .abs (s .indexOf (key ) - indexInT );
15+ }
16+ // int sumDifference = 0;
17+ // for (int i = 0; i < s.length(); i++) {
18+ // char currentChar = s.charAt(i);
19+ // int indexInT = t.indexOf(currentChar);
20+ // int difference = Math.abs(i - indexInT);
21+ // sumDifference += difference;
22+
23+ return permDifferences ;
2024 }
2125}
You can’t perform that action at this time.
0 commit comments