Share my solution by using map


  • 0
    W

    bool isAnagram(string s, string t)
    {
    int sSize = s.size();
    int tSize = t.size();

        if(sSize != tSize)
            return false;
            
        map<char, int>smap;
        map<char, int>tmap;
        
        for(int i=0; i < sSize; i++)
        {
            smap[s[i]]++;
            tmap[t[i]]++;
        }
        
        if(smap != tmap)
            return false;
        else
            return true;
    
    }

Log in to reply
 

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