-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path335.py
More file actions
25 lines (20 loc) · 776 Bytes
/
335.py
File metadata and controls
25 lines (20 loc) · 776 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
class Solution:
def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str:
digits = [0 for _ in range(26)]
for x in licensePlate.lower():
if x not in "1234567890 ":
digits[ord(x) - ord('a')] += 1
res = "aaaaaaaaaaaaaaaaaaaa"
cnt = sum(digits)
for word in words:
c = 0
digits_clone = [x for x in digits]
for x in word.lower():
if x not in "1234567890 " and digits_clone[ord(x) - ord('a')] > 0:
c += 1
digits_clone[ord(x) - ord('a')] -= 1
if c >= cnt:
break
if c >= cnt and len(word) < len(res):
res = word
return res