每日一题 2085. 统计出现过一次的公共字符串(简单)

在这里插入图片描述

class Solution:
    def countWords(self, words1: List[str], words2: List[str]) -> int:
        cnt1 = defaultdict(int)
        cnt2 = defaultdict(int)
        for w in words1:
            cnt1[w] += 1
        for w in words2:
            cnt2[w] += 1
        ans = 0
        for w in cnt1.keys():
            if cnt1[w] == 1 and cnt2[w] == 1:
                ans += 1
        return ans

你可能感兴趣的:(用Python刷力扣,算法,leetcode,python)