Skip to content

Commit 9938a60

Browse files
committed
update
1 parent 5eb168e commit 9938a60

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

code/748.最短补全词.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# @lc app=leetcode.cn id=748 lang=python3
3+
#
4+
# [748] 最短补全词
5+
#
6+
7+
# @lc code=start
8+
class Solution:
9+
10+
def getLen(self, lp, ws):
11+
12+
for l in lp:
13+
ws.remove(l)
14+
15+
return len(ws)
16+
17+
def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str:
18+
lp = []
19+
for l in licensePlate:
20+
if 'a' <= l <= 'z' or 'A' <= l <= 'Z':
21+
lp.append(l.lower())
22+
res = None
23+
resL = -1
24+
for word in words:
25+
try:
26+
l = self.getLen(lp, list(word))
27+
if res is None or resL > l:
28+
res = word
29+
resL = l
30+
except:
31+
pass
32+
33+
return res
34+
# @lc code=end
35+

0 commit comments

Comments
 (0)