1160. 拼写单词

时间:2020-06-17 22:03:47   收藏:0   阅读:59

1160. 拼写单词

技术分享图片

 

 map映射字符个数比较:

 

class Solution {
public:
    int countCharacters(vector<string>& words, string chars) {
        map<char,int>mp;
        for(int i=0;i<chars.length();i++)
        {
            mp[chars[i]]++;
        }
        int len=0;
        for(int i=0;i<words.size();i++)
        {
            string s=words[i];
            bool flag=false;
            map<char,int>mp1;
            for(int j=0;j<s.length();j++)
            {
                mp1[s[j]]++;
            }
            for(int k=0;k<s.length();k++)
            {
                if(mp1[s[k]]>mp[s[k]])
                {
                    flag=true;
                    break;
                }
            }
            if(!flag)
                len+=s.length();
        }
        return len;
    }
};

 

原文:https://www.cnblogs.com/Vampire6/p/13154667.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!