判断words里面每一个word是否能由chars中的字母组成,输出所有可以组成的word的总长度,用python的count
1 #1160
2 #Runtime: 71 ms (Beats 71.98%)
3 #Memory: 14.4 MB (Beats 7.69%)
4
5 class Solution(object):
6 def countCharacters(self, words, chars):
7 """
8 :type words: List[str]
9 :type chars: str
10 :rtype: int
11 """
12 ans = ''
13 for w in words:
14 for ch in w:
15 if chars.count(ch) < w.count(ch):
16 break
17 else:
18 ans += w
19 return len(ans)