Simple solution by Java 8 Stream


  • 0
    X
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }
        
        final int[] occurs = s.chars().collect(() -> new int[26], (a, ch) -> a[ch - 'a']++, (a, b) -> {});
        return t.chars().noneMatch(ch -> --occurs[ch-'a'] < 0);
    }
    

Log in to reply
 

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