File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments