16ms C++ solution


  • 0
    X

    class Solution {
    public:
    bool isAnagram(string s, string t) {
    if(s == t) return true;
    if(s.length() != t.length()) return false;
    map<char,int>s1;
    map<char,int>t1;
    for(int i = 0; i < s.length(); i++){
    s1[s[i]]++;
    t1[t[i]]++;
    }
    if (s1.size() != t1.size()) return false;
    map<char,int>::iterator it_s;
    map<char,int>::iterator it_t;
    for(it_s = s1.begin(),it_t = t1.begin(); it_s != s1.end(); it_t++,it_s++){
    if(it_s->first != it_t->first || it_s->second != it_t->second)
    return false;
    }
    return true;
    }
    };


Log in to reply
 

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