File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 1 file changed +16
-5
lines changed 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
5- /**
6- * Provide the solution to LeetCode 3146 here:
7- * https://leetcode.com/problems/permutation-difference-between-two-strings
8- */
97 public int findPermutationDifference (String s , String t ) {
10- return 0 ;
8+
9+ HashMap <Character , Integer > indexMap = new HashMap <>();
10+ for (int i = 0 ; i < s .length (); i ++) {
11+ indexMap .put (s .charAt (i ), i );
12+ }
13+ // calculating the difference
14+ int difference = 0 ;
15+ for (int i = 0 ; i < t .length (); i ++) {
16+ if (indexMap .containsKey (t .charAt (i ))) {
17+ difference += Math .abs (indexMap .get (t .charAt (i )) - i );
18+ }
19+ }
20+ return difference ;
1121 }
1222}
23+ // I got help from chat gpt and co pilot. I used chat gpt to further explain the code that I was putting in.
You can’t perform that action at this time.
0 commit comments