Accepted short Java solution


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