4.LeetCode(初级算法)字符串篇-有效的字母异位词C++

class Solution {
public:
    bool isAnagram(string s, string t) {
        unordered_map map_s;
        unordered_map map_t;
        for(auto c : s) map_s[c]++;
        for(auto c : t) map_t[c]++;
        
        if(map_s.size() != map_t.size()) return false;
        for(auto elem : map_s)
        {
            if(map_t.find(elem.first) == map_t.end()) return false;
            if(map_t.at(elem.first) != elem.second) return false;
        }
        return true;
    }
};

你可能感兴趣的:(LeetCode)