Accepted Java O(n) solution in 5 lines
The idea is simple. It creates a size 26 int arrays as buckets for each letter in alphabet. It increments the bucket value with String s and decrement with stri
The idea is simple. It creates a size 26 int arrays as buckets for each letter in alphabet. It increments the bucket value with String s and decrement with string t. So if they are anagrams, all buckets should remain with initial value which is zero. So just checking that and return\n\n    public class Solution {\n        public boolean isAnagram(String s, String t) {\n            int[] alphabet = new int[26];\n            for (int i = 0; i < s.length(); i++) alphabet[s.charAt(i) - 'a']++;\n            for (int i = 0; i < t.length(); i++) alphabet[t.charAt(i) - 'a']--;\n            for (int i : alphabet) if (i != 0) return false;\n            return true;\n        }\n    }
['Java']