Skip to content

Commit 13a1a25

Browse files
committed
Feat:Adds Lesson13.java/ts for NileJackson
1 parent 32f5984 commit 13a1a25

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package com.codedifferently.lesson13;
22

3+
import java.util.HashMap;
4+
35
public 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+
HashMap<Character, Integer> ABC = new HashMap<>();
13+
int permDiff = 0;
14+
for (int i = 0; i < s.length(); i++) {
15+
ABC.put(s.charAt(i), i);
16+
}
17+
18+
for (char key : ABC.keySet()) {
19+
int indexInT = t.indexOf(Character.toString(key));
20+
21+
permDiff += Math.abs(s.indexOf(key) - indexInT);
22+
}
23+
return permDiff;
1124
}
1225
}

lesson_13/maps_ts/src/lesson13.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@
33
* https://leetcode.com/problems/permutation-difference-between-two-strings
44
*/
55
export function findPermutationDifference(s: string, t: string): number {
6-
return 0;
6+
const ABC = new Map<string, number>();
7+
let permDiff = 0;
8+
for (let i = 0; i < s.length; i++) {
9+
ABC.set(s.charAt(i), i);
10+
}
11+
12+
for (const key of ABC.keys()) {
13+
const indexInT = t.indexOf(key);
14+
permDiff += Math.abs(s.indexOf(key) - indexInT);
15+
}
16+
return permDiff;
717
}

0 commit comments

Comments
 (0)