Skip to content

Commit 2a47512

Browse files
committed
task:added lesson 13 work into branch
1 parent abb394d commit 2a47512

File tree

1 file changed

+16
-5
lines changed
  • lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13

1 file changed

+16
-5
lines changed
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
package com.codedifferently.lesson13;
22

3+
import java.util.HashMap;
4+
35
public class Lesson13 {
46

5-
/**
6-
* Provide the solution to LeetCode 3146 here:
7-
* https://leetcode.com/problems/permutation-difference-between-two-strings
8-
*/
97
public int findPermutationDifference(String s, String t) {
10-
return 0;
8+
9+
HashMap<Character, Integer> indexMap = new HashMap<>();
10+
for (int i = 0; i < s.length(); i++) {
11+
indexMap.put(s.charAt(i), i);
12+
}
13+
// calculating the difference
14+
int difference = 0;
15+
for (int i = 0; i < t.length(); i++) {
16+
if (indexMap.containsKey(t.charAt(i))) {
17+
difference += Math.abs(indexMap.get(t.charAt(i)) - i);
18+
}
19+
}
20+
return difference;
1121
}
1222
}
23+
// I got help from chat gpt and co pilot. I used chat gpt to further explain the code that I was putting in.

0 commit comments

Comments
 (0)