2085.统计出现过一次的公共字符串
链接:2085.统计出现过一次的公共字符串
难度:Easy
标签:数组、哈希表、字符串、计数
简介:给你两个字符串数组 words1 和 words2 ,请你返回在两个字符串数组中 都恰好出现一次 的字符串的数目。
题解 1 - python
- 编辑时间:2024-01-12
- 执行用时:52ms
- 内存消耗:17.23MB
- 编程语言:python
- 解法介绍:计数。
class Solution:
def countWords(self, words1: List[str], words2: List[str]) -> int:
c1 = Counter(words1)
c2 = Counter(words2)
return sum(v == 1 and c2[k] == 1 for k, v in c1.items())