-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortestCompletingWord.py
37 lines (31 loc) · 1.13 KB
/
shortestCompletingWord.py
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
28
29
30
31
32
33
34
35
36
37
class Solution:
def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str:
licensePlate =licensePlate.lower()
isAlpha = set(list('abcdefghijklmnopqrstuvwxyz'))
stVal = {}
for i in range(0,len(licensePlate)):
if licensePlate[i] in isAlpha:
if licensePlate[i] in stVal:
stVal[licensePlate[i]]+=1
else:
stVal[licensePlate[i]]=1
ans = ""
from collections import Counter
for i in range(0,len(words)):
boo = False
li = Counter(words[i])
for key in stVal:
if key in li:
if stVal[key] <= li[key]:
continue
else:
boo = True
else:
boo = True
if boo == False:
if ans == "":
ans = words[i]
else:
if len(ans)> len(words[i]):
ans = words[i]
return ans