Skip to content

Commit

Permalink
Create 1347-minimum-number-of-steps-to-make-two-strings-anagram.java
Browse files Browse the repository at this point in the history
  • Loading branch information
sujal-goswami authored Jan 13, 2024
1 parent c3ebddb commit b98a126
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions java/1347-minimum-number-of-steps-to-make-two-strings-anagram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*-------------------------------
Time Complexity: O(n)
Space Complexity: O(n)
--------------------------------*/
class Solution {
public int minSteps(String s, String t) {
Map<Character, Integer> map1 = new HashMap<>();
for(char c: s.toCharArray())
map1.put(c, map1.getOrDefault(c, 0) + 1);

int res = 0;
for(char c: t.toCharArray()){
if(map1.containsKey(c) && map1.get(c) > 0){
map1.put(c, map1.get(c)-1);
}
else{
res++;
}
}
return res;
}
}

0 comments on commit b98a126

Please sign in to comment.