iven two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Input: s = "anagram", t = "nagaram" Output: true
Example 2:
Input: s = "rat", t = "car" Output: false
Note:
You may assume the string contains only lowercase alphabets.
class Solution {
public:
bool isAnagram(string s, string t) {
map<char,int> maps;
for(int i=0;i<s.size();i++)
{
if(maps.find(s[i])==maps.end())
{
maps[s[i]]=1;
}
else
{
maps[s[i]]++;
}
}
for(int i=0;i<t.size();i++)
{
if(maps.find(t[i])==maps.end())
return false;
else
maps[t[i]]--;
}
for(int i=0;i<s.size();i++)
{
if(maps[s[i]]!=0)
return false;
}
return true;
}
};