File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 1 file changed +19
-5
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
5- /**
6- * Provide the solution to LeetCode 3146 here:
7- * https://leetcode.com/problems/permutation-difference-between-two-strings
8- */
8+
99 public int findPermutationDifference (String s , String t ) {
10- return 0 ;
10+
11+ Map <Character , Integer > sIndexMap = new HashMap <>();
12+ for (int i = 0 ; i < s .length (); i ++) {
13+ sIndexMap .put (s .charAt (i ), i );
14+ }
15+
16+ int totalDifference = 0 ;
17+
18+ for (int i = 0 ; i < t .length (); i ++) {
19+ char currentChar = t .charAt (i );
20+ int indexInS = sIndexMap .get (currentChar );
21+ totalDifference += Math .abs (indexInS - i );
22+ }
23+
24+ return totalDifference ;
1125 }
1226}
You can’t perform that action at this time.
0 commit comments