class Solution1(object):def findLongestWord(self, s, d):"""按照长度和字典序排序&#xff0c;然后找出第一个满足条件的单词即可"""d.sort(key&#61;lambda x:(-len(x), x))for word in d:if self.match(s, word):return wordreturn ""def match(self, parent, son):index &#61; 0for char in parent:if char &#61;&#61; son[index]:index &#43;&#61; 1if index &#61;&#61; len(son):return Truereturn Falseclass Solution(object):"""非排序"""def findLongestWord(self, s, d):result &#61; ""for word in d:if self.match(s, word):if len(word) > len(result):result &#61; wordcontinueif len(word) &#61;&#61; len(result):if word < result:result &#61; wordreturn resultdef match(self, parent, son):index &#61; 0for char in parent:if char &#61;&#61; son[index]:index &#43;&#61; 1if index &#61;&#61; len(son):return Truereturn False