Java simple solution without hashmap


  • 0
    D
    public boolean isAnagram(String s, String t) {
        int[] counter = new int[26];
        for (int c : s.toCharArray())
            counter[c - 'a']++;
    
        for (int c : t.toCharArray())
            counter[c - 'a']--;
        return Arrays.stream(counter).allMatch(x -> x == 0);
    }

Log in to reply
 

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