C++ implementation


  • 7
    class Solution {
    public:
        bool isAnagram(string s, string t) {
            if(s.size() != t.size())    return false;
            int n=s.size();
            vector<int> counts(128, 0);
            for(int i=0; i<n; i++)
            {
                counts[s[i]]++;
                counts[t[i]]--;
            }
            for(auto count:counts)
                if(count)   return false;
            return true;
        }
    };

Log in to reply
 

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