There was an error while loading. Please reload this page.
1 parent 5eb168e commit 9938a60Copy full SHA for 9938a60
code/748.最短补全词.py
@@ -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