【Leetcode383】Ransom Note

class Solution {
public:
    bool canConstruct(string ransomNote, string magazine) {
        std::vector<int> bag(26, 0);
        for(const auto& c : magazine){
            bag[c-'a']++;
        }
        for(const auto& c : ransomNote){
            if(!bag[c-'a'])
                return false;
            else
                bag[c-'a']--;
        }
        return true;
    }
};

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章