Leetcode 916. Word Subsets

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Word Subsets

2. Solution

  • Version 1
1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
def wordSubsets(self, A, B):
result = []
stat = Counter()
for b in B:
stat |= Counter(b)

for a in A:
temp = Counter(a)
diff = stat - temp
if len(diff) == 0:
result.append(a)
return result

Reference

  1. https://leetcode.com/problems/word-subsets/
如果有收获,可以请我喝杯咖啡!