Minimum Number of Steps to Make Two Strings Anagram II LeetCode solution in Java

1
class Solution {
2
public int minSteps(String s, String t) {
3
HashMap<Character, Integer> hmap = new HashMap<>();
4
for (char ch : s.toCharArray()) hmap.put(ch, hmap.getOrDefault(ch, 0) + 1);
5
for (char ch : t.toCharArray()) hmap.put(ch, hmap.getOrDefault(ch, 0) - 1);
6
int count = 0;
7
for (char key : hmap.keySet()) if (hmap.get(key) != 0) count += (Math.abs(hmap.get(key)));
8
return count;
9
}
10
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0