Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ public class Lesson13 {
* https://leetcode.com/problems/permutation-difference-between-two-strings
*/
public int findPermutationDifference(String s, String t) {
return 0;
int ans = 0;
int[] indices = new int[26];

for (int i = 0; i < s.length(); ++i) {
indices[s.charAt(i) - 'a'] = i;
}

for (int i = 0; i < t.length(); ++i) {
ans += Math.abs(indices[t.charAt(i) - 'a'] - i);
}

return ans;
}
}
12 changes: 11 additions & 1 deletion lesson_13/maps_ts/src/lesson13.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to solve these build problems

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@
* https://leetcode.com/problems/permutation-difference-between-two-strings
*/
export function findPermutationDifference(s: string, t: string): number {
return 0;
let ans: number = 0;

Check failure on line 6 in lesson_13/maps_ts/src/lesson13.ts

View workflow job for this annotation

GitHub Actions / build

Type number trivially inferred from a number literal, remove type annotation
let indices: number[] = new Array(26).fill(0);

Check failure on line 7 in lesson_13/maps_ts/src/lesson13.ts

View workflow job for this annotation

GitHub Actions / build

'indices' is never reassigned. Use 'const' instead

for (let i = 0; i < s.length; ++i){
indices[s.charCodeAt(i) - 'a'.charCodeAt(0)] = i;
}

for (let i = 0; i < t.length; ++i){
ans += Math.abs(indices[t.charCodeAt(i) - 'a'.charCodeAt(0)] - i);
}
return ans;
}
Loading