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 1
1
package com .codedifferently .lesson13 ;
2
2
3
+ import java .util .HashMap ;
4
+
3
5
public class Lesson13 {
4
6
5
7
/**
6
8
* Provide the solution to LeetCode 3146 here:
7
9
* https://leetcode.com/problems/permutation-difference-between-two-strings
8
10
*/
9
11
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 ;
11
22
}
12
23
}
Original file line number Diff line number Diff line change 3
3
* https://leetcode.com/problems/permutation-difference-between-two-strings
4
4
*/
5
5
export 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 ;
7
16
}
You can’t perform that action at this time.
0 commit comments