Simple Java solution beats 98%!


  • 2
    D
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;
        int[] count = new int[26];
        for (char c : s.toCharArray()) {
            count[c - 'a']++;
        }
        for (char c : t.toCharArray()) {
            count[c - 'a']--;
            if (count[c - 'a'] < 0) return false;
        }
        return true;
    }

  • 0
    L

    Nice!! A good hash table sort of implementation


Log in to reply
 

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