Skip to content

Commit dc071ab

Browse files
authored
Create count-common-words-with-one-occurrence.py
1 parent 1490f3b commit dc071ab

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(m + n)
2+
# Space: O(m + n)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def countWords(self, words1, words2):
9+
"""
10+
:type words1: List[str]
11+
:type words2: List[str]
12+
:rtype: int
13+
"""
14+
cnt = collections.Counter(words1)
15+
for c in words2:
16+
if cnt[c] < 2:
17+
cnt[c] -= 1
18+
return sum(v == 0 for v in cnt.itervalues())

0 commit comments

Comments
 (0)