C++ 6 lines solution


  • 1
     bool isAnagram(string s, string t) {
            if(s.size()!=t.size()) return false;
            unordered_map<char,int>m(26);
            for(auto c:t) m[c]++;
            for(int i=0;i<s.size();i++) 
                if(m[s[i]]--<=0) return false;
            return true;
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.