1160. 拼写单词
作者:互联网
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; } };
标签:1160,int,len,拼写,单词,flag 来源: https://www.cnblogs.com/Vampire6/p/13154667.html