Skip to content

Commit 117f0a9

Browse files
committed
Feat: Implemented Hashmap to lesson 13 by Hummad Tanweer
1 parent 32f5984 commit 117f0a9

File tree

1 file changed

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

1 file changed

+16
-1
lines changed
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
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
*/
11+
912
public int findPermutationDifference(String s, String t) {
10-
return 0;
13+
14+
//var charLocation = new HashMap<Character, Integer>();
15+
16+
HashMap<Character,Integer> map = new HashMap();
17+
int sum=0;
18+
for(int i =0; i< s.length(); i++) {
19+
map.putIfAbsent(s.charAt(i),i);
20+
}
21+
for(char key: map.keySet()) {
22+
int indexInt = t.indexOf(Character.toString(key));
23+
sum += Math.abs (s.indexOf(key)- indexInt);
24+
}
25+
return sum;
1126
}
1227
}

0 commit comments

Comments
 (0)