We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 981f5cd commit 8feca19Copy full SHA for 8feca19
DFS/traditionalDFS/916.md
@@ -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