Skip to content

Commit b1c6bba

Browse files
committed
100124
1 parent 8a109c6 commit b1c6bba

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from typing import List
2+
3+
4+
# leetcode submit region begin(Prohibit modification and deletion)
5+
class Solution:
6+
def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:
7+
b = [0] * 26
8+
for w in words2:
9+
counter = [0] * 26
10+
for c in w:
11+
idx = ord(c) - ord('a')
12+
counter[idx] += 1
13+
for i in range(26):
14+
if counter[i] == 0:
15+
continue
16+
b[i] = max(b[i], counter[i])
17+
ans = []
18+
for w in words1:
19+
counter = [0] * 26
20+
for c in w:
21+
idx = ord(c) - ord('a')
22+
counter[idx] += 1
23+
good = True
24+
for i in range(26):
25+
if b[i] > counter[i]:
26+
good = False
27+
break
28+
if good:
29+
ans.append(w)
30+
return ans
31+
32+
33+
# leetcode submit region end(Prohibit modification and deletion)
34+
35+
36+
class WordSubsets(Solution):
37+
pass

0 commit comments

Comments
 (0)