Explained Code || Used Hashing || JAVA Code
\n\n# Approach\nThe code uses a HashMap to count the frequency of each character in the first string s. For each character in s, if the character is not already
\n\n# Approach\nThe code uses a HashMap to count the frequency of each character in the first string s. For each character in s, if the character is not already in the map, it is added with a frequency of 1. If the character is already in the map, the frequency is incremented by 1.\n\nThen, for each character in string t, the code checks if the character is in the map. If it is, the frequency of the character is decremented by 1. If the frequency becomes 1, the character is removed from the map. If the frequency becomes 0, the character is not removed but the frequency is updated. If the character is not in the map, the code immediately returns false because it indicates that there is a character in t that is not in s.\n\nFinally, after processing all characters in t, if the map is empty, it means that the frequency of all characters in s and t matched, and the strings are anagrams, so the code returns true. Otherwise, the code returns false because some characters in s had different frequencies in t.\n\n# Complexity\n- Time complexity:\nThe time complexity of this code is O(n), where n is the length of the longest string. This is because, for both strings, each character is processed once.\n\n- Space complexity:\nThe space complexity is O(1), because the frequency count is stored in a HashMap, and the size of the map is proportional to the number of unique characters in the input strings, which is constant and limited to the size of the character set (usually 128 or 256).\n\n\n\n\n# Code\n```\nclass Solution {\n    public boolean isAnagram(String s, String t) {\n        HashMap<Character, Integer> map = new HashMap<>();\n        for(int i=0;i<s.length();i++){\n            char ch = s.charAt(i);\n            map.put(ch,map.getOrDefault(ch,0)+1);\n        }\n        for(int i=0;i<t.length();i++){\n            char ch = t.charAt(i);\n            if(map.get(ch)!=null){\n                if(map.get(ch)==1){\n                    map.remove(ch);\n                }else{\n                    map.put(ch,map.get(ch)-1);\n                }\n            }else{\n                return false;\n            }\n        }\n        return map.isEmpty();\n    }\n}\n```\n![upvote.jpeg](https://assets.leetcode.com/users/images/fa82847d-19f3-43fb-a5ba-27f52d06e5b0_1675500966.3666072.jpeg)\n
['Hash Table', 'Java']