C++| 3 Solutions| Map | Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \n1.We can just sort and check if both the strings are equal.\n2. Can use hash map and ch
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1.We can just sort and check if both the strings are equal.\n2. Can use hash map and check if occurence of every element in `s` is present in `t`;\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**Sorting**\n**Hash Map**\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(26)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n**Using Sorting**\n```\n bool isAnagram(string s, string t) {\n        sort(begin(s),end(s));\n        sort(begin(t),end(t));\n       return s==t;\n    }\n```\n**Using Hash Map**\n```\n bool isAnagram(string s, string t) {\n        vector<int>mp(26,0),mp2(26,0);\n        if(s.size()>t.size())return false;\n        for(auto x:s)mp[x-\'a\']++;\n        for(auto x:t){\n            if(mp[x-\'a\']<=0)return false;\n            mp[x-\'a\']--;\n        }\n        return true;\n    }\n```\n**Using Hash Map little better in time**\n```\nclass Solution {\npublic:\n    bool isAnagram(string s, string t) {\n        vector<int>mp(26,0);\n        if(s.size()!=t.size())return false;\n        for(int i=0;i<s.size();i++){\n           mp[s[i]-\'a\']++; \n           mp[t[i]-\'a\']--;\n        }\n        for(int i=0;i<26;i++){\n            if(mp[i]!=0)return false;\n        }\n        return true;\n    }\n};\n```
['Hash Table', 'String', 'Sliding Window', 'Sorting', 'C++']