2ms java solution beats 99.72% without hashmap or sort

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