Skip to content

Commit 69116ae

Browse files
committed
2020-03-16
1 parent 480be5b commit 69116ae

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution(object):
2+
def countCharacters(self, words, chars):
3+
"""
4+
:type words: List[str]
5+
:type chars: str
6+
:rtype: int
7+
"""
8+
res = 0
9+
from collections import Counter
10+
11+
dic_a = Counter(chars)
12+
13+
for word in words:
14+
dic_w = Counter(word)
15+
flag = 1
16+
for key, val in dic_w.items():
17+
if key not in dic_a or dic_a[key] < val:
18+
flag = 0
19+
break
20+
if flag:
21+
res += len(word)
22+
23+
return res

0 commit comments

Comments
 (0)