LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.6MB, accepted 2025-12-29.

python
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

Source