Problem Statement
Two strings are anagrams if:
Explanation
Anagrams have identical characters with identical counts but possibly different orders. For example, 'listen' and 'silent' are anagrams. Sorting or frequency counting is used to check this efficiently.
Code Solution
SolutionRead Only
boolean isAnagram(String a,String b){
if(a.length()!=b.length()) return false;
int[] count=new int[26];
for(char c:a.toCharArray()) count[c-'a']++;
for(char c:b.toCharArray()) count[c-'a']--;
for(int x:count) if(x!=0) return false;
return true; }Practice Sets
This question appears in the following practice sets:
