Last active
October 4, 2017 00:31
-
-
Save shailrshah/c53887d73e205f5943d8532e4e33fa63 to your computer and use it in GitHub Desktop.
Return true iff the two given strings have the same character frequencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static boolean isAnagram(String a, String b) { | |
if(a.length() != b.length()) return false; | |
return Arrays.equals(getCount(a.toLowerCase()), getCount(b.toLowerCase())); | |
} | |
static int[] getCount(String str) { | |
int[] count = new int[26]; | |
str.chars().forEach(ch -> count[ch-'a']++); | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment