[Java] TC:O(N) | SC:O(1) | Simple & Concise HashMap solution (w/o Sorting)
java\n/**\n * Time Complexity: O(N)\n *\n * Space Complexity: O(N)\n *\n * N = Length of input string S or T.\n */\nclass Solution {\n    public boolean isAnagr
```java\n/**\n * Time Complexity: O(N)\n *\n * Space Complexity: O(N)\n *\n * N = Length of input string S or T.\n */\nclass Solution {\n    public boolean isAnagram(String s, String t) {\n        if (s == null || t == null || s.length() != t.length()) {\n            return false;\n        }\n\n        int len = s.length();\n        // Finding the count of each character in string S\n        HashMap<Character, Integer> countMap = new HashMap<>();\n        for (int i = 0; i < len; i++) {\n            char c = s.charAt(i);\n            countMap.put(c, countMap.getOrDefault(c, 0) + 1);\n        }\n\n        // Subtracting the count for each character in string T.\n        // If an extra char is found, we can return false.\n        for (int i = 0; i < len; i++) {\n            char c = t.charAt(i);\n            Integer count = countMap.get(c);\n            if (count == null) {\n                return false;\n            }\n            if (count.equals(1)) {\n                countMap.remove(c);\n            } else {\n                countMap.put(c, count - 1);\n            }\n        }\n\n        return true;\n    }\n}\n```\n\n---\n**Below solution can take twice extra space if all characters in S & T are different.**\n```java\n/**\n * Time Complexity: O(N)\n *\n * Space Complexity: O(2*N) = O(N). In worst case if both strings have all\n * different characters, then map will have 2*N chars.\n *\n * N = Length of input string S or T.\n */\nclass Solution {\n    public boolean isAnagram(String s, String t) {\n        if (s == null || t == null || s.length() != t.length()) {\n            return false;\n        }\n\n        int len = s.length();\n        // Finding the diff count of all characters in S & T\n        HashMap<Character, Integer> countMap = new HashMap<>();\n        for (int i = 0; i < len; i++) {\n            char charS = s.charAt(i);\n            char charT = t.charAt(i);\n            countMap.put(charS, countMap.getOrDefault(charS, 0) + 1);\n            countMap.put(charT, countMap.getOrDefault(charT, 0) - 1);\n        }\n\n        if (countMap.size() > len) {\n            return false;\n        }\n\n        // All Diff Counts should be zero.\n        // If not, then return false.\n        for (int count : countMap.values()) {\n            if (count != 0) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n}\n```
['Java']