Leetcode 1002. Find Common Characters

时间:2023-03-09 03:48:28
Leetcode 1002. Find Common Characters

python可重集合操作

class Solution(object):
def commonChars(self, A):
"""
:type A: List[str]
:rtype: List[str]
"""
if not A:
return []
from collections import Counter
ans=Counter(A[0])
for str in A:
ans&=Counter(str)
ans=list(ans.elements())
return ans