2190. Count Common Words With One Occurrence
My accepted Python solution to LeetCode problem 2190, Count Common Words With One Occurrence, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 17.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 3ms, memory 17.6MB, accepted 2025-12-29.
class Solution:
def countWords(self, words1: List[str], words2: List[str]) -> int:
from collections import Counter
count1 = Counter(words1)
count2 = Counter(words2)
result = 0
for word in count1:
if count1[word] == 1 and count2.get(word, 0) == 1:
result += 1
return result