力扣第1160题 拼写单词

力扣第1160题 拼写单词

class Solution {
    public:
    int countCharacters(vector<string>& words, string chars)
     {
        map<char, int> m_Map;
        for (char c : chars)
            ++m_Map[c];
        int res = 0;
        for (string word : words)
        {
            map<char, int> temp;
            for (char c : word)
                ++temp[c];
            bool is_word = true;
            for (char c : word)
            {
                if (m_Map[c] < temp[c])
                {
                    is_word = false;
                    break;
                }
            }
            if (is_word)
            {
                res += word.size();
            }
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/woodjay/p/12514255.html