leetcode242 有效的字母异位词 Valid Anagram

class Solution {
public:
    bool isAnagram(string s, string t) {
        sort(s.begin(),s.end());
        sort(t.begin(),t.end());
        return s==t;
    }
};
class Solution {
public:
    bool isAnagram(string s, string t) {
        if(s.size()!=t.size()) return false;
        vector<int> hash(256,0);
        for(int i=0;i<s.size();++i){
            ++hash[s[i]];
            --hash[t[i]];
        }
        return hash==vector<int>(256,0);
    }
};
posted @ 2019-07-06 19:28  天涯海角路  阅读(72)  评论(0)    收藏  举报