class Solution { public: bool isAnagram(string s, string t) { if(t=="") return s==""; map<char,int> m_s; map<char,int> m_t; int i=0; while(i<t.length()){ if(m_t.find(t[i]) != m_t.end()) m_t[t[i]]++; else m_t.insert(pair<char,int>(t[i],1)); i++; } i=0; while(i<s.length()){ if(m_s.find(s[i]) != m_s.end()) m_s[s[i]]++; else m_s.insert(pair<char,int>(s[i],1)); i++; } map<char,int >::iterator it; for(it=m_s.begin();it!=m_s.end();it++){ //s belong t if(m_t[it->first] != it->second) {return false;} } for(it=m_t.begin();it!=m_t.end();it++){ //t belong s if(m_s[it->first] != it->second) {return false;} } return true; } };