Java O(n) solution for strings of arbitrary characters
The idea is to count how much of each character strings contain. If two strings are anagrams, they should contain the equal number of particular characters. Siz
The idea is to count how much of each character strings contain. If two strings are anagrams, they should contain the equal number of particular characters. Size of array is chosen according to the size of ASCII table.\n\n       public class Solution {\n            public boolean isAnagram(String s, String t) {\n                if (s.length()!=t.length()) return false;\n                int[] c=new int[256];\n                for (int i=0; i<s.length(); ++i){\n                    c[s.charAt(i)]++; \n                    c[t.charAt(i)]--;\n                }\n                \n                for (int i=0; i<256; ++i){\n                    if (c[i]!=0) return false;\n                }\n                return true;\n            }\n        }
[]