-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path748.py
More file actions
29 lines (28 loc) · 885 Bytes
/
Copy path748.py
File metadata and controls
29 lines (28 loc) · 885 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
28
29
class Solution(object):
def shortestCompletingWord(self, licensePlate, words):
"""
:type licensePlate: str
:type words: List[str]
:rtype: str
"""
checkmsg = ''.join([licensePlate[i].lower() for i in range(len(licensePlate)) if licensePlate[i].isalpha()]);
ls = list(checkmsg);
ls.sort();
checkmsg = ''.join(ls);
words.sort(self.cmp);
# find checkmsg in words
for word in words:
fl = True
for letter in checkmsg:
if word.count(letter) < checkmsg.count(letter):
fl = False
break;
if fl:
return word;
def cmp(self, s1, s2):
if len(s1) > len(s2):
return 1;
elif len(s1) < len(s2):
return -1;
else:
return 0;