Simple fast Java solution


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