leetcode 242 Valid Anagram

class Solution {
public:
    bool isAnagram(string s, string t) {
        vector<int> ms(26,0),mt(26,0);
        for(auto& str:s) ++ms[str-'a'];
        for(auto& str:t) ++mt[str-'a'];
        for(int i=0;i<26;++i) {
            if(ms[i]!=mt[i]) return false;
        }
        return true;
    }
};

 

posted @ 2020-03-26 10:46  qiujiejie  阅读(91)  评论(0编辑  收藏  举报