File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 2 files changed +22
-2
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
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 bmb = new HashMap <Character , Integer >();
13+ int permDiff = 0 ;
14+ for (int i = 0 ; i < s .length (); i ++) {
15+ bmb .put (s .charAt (i ), i );
16+ }
17+ for (char key : bmb .keySet ()) {
18+ int indexInT = t .indexOf (Character .toString (key ));
19+ permDiff += Math .abs (s .indexOf (key ) - indexInT );
20+ }
21+ return permDiff ;
1122 }
1223}
Original file line number Diff line number Diff line change 33 * https://leetcode.com/problems/permutation-difference-between-two-strings
44 */
55export function findPermutationDifference ( s : string , t : string ) : number {
6- return 0 ;
6+ const bmb = new Map < string , number > ( ) ;
7+ let permDiff = 0 ;
8+ for ( let i = 0 ; i < s . length ; i ++ ) {
9+ bmb . set ( s . charAt ( i ) , i ) ;
10+ }
11+ for ( const key of bmb . keys ( ) ) {
12+ const indexInT = t . indexOf ( key ) ;
13+ permDiff += Math . abs ( s . indexOf ( key ) - indexInT ) ;
14+ }
15+ return permDiff ;
716}
You can’t perform that action at this time.
0 commit comments