Skip to content

Commit b98a126

Browse files
Create 1347-minimum-number-of-steps-to-make-two-strings-anagram.java
1 parent c3ebddb commit b98a126

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*-------------------------------
2+
Time Complexity: O(n)
3+
Space Complexity: O(n)
4+
--------------------------------*/
5+
class Solution {
6+
public int minSteps(String s, String t) {
7+
Map<Character, Integer> map1 = new HashMap<>();
8+
for(char c: s.toCharArray())
9+
map1.put(c, map1.getOrDefault(c, 0) + 1);
10+
11+
int res = 0;
12+
for(char c: t.toCharArray()){
13+
if(map1.containsKey(c) && map1.get(c) > 0){
14+
map1.put(c, map1.get(c)-1);
15+
}
16+
else{
17+
res++;
18+
}
19+
}
20+
return res;
21+
}
22+
}

0 commit comments

Comments
 (0)