-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0916_Word_Subsets.py
More file actions
27 lines (23 loc) · 866 Bytes
/
0916_Word_Subsets.py
File metadata and controls
27 lines (23 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:
maxCharFreq = [0] * 26
tempCharFreq = [0] * 26
for word in words2:
for ch in word:
tempCharFreq[ord(ch) - ord('a')] += 1
for i in range(26):
maxCharFreq[i] = max(maxCharFreq[i], tempCharFreq[i])
tempCharFreq = [0] * 26
universalWords = []
for word in words1:
for ch in word:
tempCharFreq[ord(ch) - ord('a')] += 1
isUniversal = True
for i in range(26):
if maxCharFreq[i] > tempCharFreq[i]:
isUniversal = False
break
if isUniversal:
universalWords.append(word)
tempCharFreq = [0] * 26
return universalWords