Skip to content

Commit 8feca19

Browse files
committed
916
1 parent 981f5cd commit 8feca19

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

DFS/traditionalDFS/916.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## [916] Word Subsets
2+
3+
#### Description
4+
5+
[link](https://leetcode.com/problems/word-subsets/)
6+
7+
---
8+
9+
#### Solution
10+
11+
- See Code
12+
13+
---
14+
15+
#### Code
16+
17+
> 最坏情况:O(n^2)
18+
19+
```python
20+
class Solution:
21+
def wordSubsets(self, A: List[str], B: List[str]) -> List[str]:
22+
cnt = collections.Counter()
23+
for b in B:
24+
c = collections.Counter(b)
25+
for i, x in c.items():
26+
cnt[i] = max(x, cnt[i])
27+
28+
res = []
29+
for a in A:
30+
c = collections.Counter(a)
31+
if all(c[i] >= cnt[i] for i in cnt.keys()):
32+
res.append(a)
33+
return res
34+
```

0 commit comments

Comments
 (0)