Skip to content

Commit 414ba09

Browse files
committed
NIA_Lesson_13feat: implements findPermutationDifference method to calculate permutation difference
1 parent 261ab32 commit 414ba09

File tree

1 file changed

+10
-3
lines changed
  • lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ 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 answer = 0;
1111

12-
for (int i = 0; i < s.length(); i++) {
12+
for (int i = 0; i < s.length(); i++) {
13+
char ch = s.charAt(i);
14+
int index = t.indexOf(ch);
15+
if (index != -1) {
16+
answer += Math.abs(i - index);
17+
}
18+
return answer;`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
19+
20+
})
1321
}
14-
}

0 commit comments

Comments
 (0)