Two loop only, Short Java solution


  • 0
    W
    public boolean isAnagram(String s, String t) {
        if(s.length() != t.length()) return false;
        int map[] = new int[26];
        for(char c: t.toCharArray()) {
            map[c-'a']++;
        }
        
        for(char c : s.toCharArray()) {
            map[c-'a']--;
            if(map[c-'a'] < 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.