Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-01-10_00-30-16.png
41.6 KB
#N242. Valid Anagram
problem link

#solution
class Solution {
public boolean isAnagram(String s, String t) {
if(s.length() != t.length()) return 0==1;
Map<Character, Integer> mapS = new HashMap<>();
Map<Character, Integer> mapT = new HashMap<>();

for(int i=0; i<s.length(); i++){
mapS.put(s.charAt(i), mapS.getOrDefault(s.charAt(i), 0) +1);
mapT.put(t.charAt(i), mapT.getOrDefault(t.charAt(i), 0) +1);
}

return mapS.equals(mapT);
}
}