Java solution - O(n), 3 ms, > 94.56%


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