Skip to content

Commit aa5ca18

Browse files
author
Meiko-S22
committed
feat: adds Meiko's lesson 13
1 parent abb394d commit aa5ca18

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13/Lesson13.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ public class Lesson13 {
77
* https://leetcode.com/problems/permutation-difference-between-two-strings
88
*/
99
public int findPermutationDifference(String s, String t) {
10-
return 0;
10+
int ans = 0;
11+
int[] indices = new int[26];
12+
13+
for (int i = 0; i < s.length(); ++i){
14+
indices[s.charAt(i) - 'a'] = i;
15+
}
16+
17+
for (int i = 0; i < t.length(); ++i){
18+
ans += Math.abs(indices[t.charAt(i) - 'a'] - i);
19+
}
20+
21+
return ans;
1122
}
1223
}

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+
let ans: number = 0;
7+
let indices: number[] = new Array(26).fill(0);
8+
9+
for (let i = 0; i < s.length; ++i){
10+
indices[s.charCodeAt(i) - 'a'.charCodeAt(0)] = i;
11+
}
12+
13+
for (let i = 0; i < t.length; ++i){
14+
ans += Math.abs(indices[t.charCodeAt(i) - 'a'.charCodeAt(0)] - i);
15+
}
16+
return ans;
717
}

0 commit comments

Comments
 (0)