2085. Count Common Words With One Occurrence

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2085

class Solution:
    def countWords(self, words1: List[str], words2: List[str]) -> int:
        cnt1 = Counter(words1)
        cnt2 = Counter(words2)
        return sum(v == 1 and cnt2[w] == 1 for w, v in cnt1.items())