Java 5 line, beat 90%


  • 0
    A
    public boolean isAnagram(String s, String t) {
        int[] freq = new int[256];
        if(s.length()!=t.length()) return false;
        for(char cr : s.toCharArray()) freq[cr]++;
        for(char cr : t.toCharArray()) if(--freq[cr]<0) return false;
        return true;        
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.