Java Anagrams

  • + 0 comments
    static boolean isAnagram(String a, String b) {
        String s1=a.toLowerCase();
        String s2=b.toLowerCase();
    
        int [] countofs1= new int[26];
        int [] countofs2= new int[26];
        for(char c:s1.toCharArray()){
            countofs1[c-'a']++;
        }
    
    
        for(char c:s2.toCharArray()){
            countofs2[c-'a']++;
        }
    
    
        for(int i=0;i<26;i++){
            if(countofs1[i] != countofs2[i]){
    
                return false;
            }
        }
    
        return true;
    
    }