python codes

  • 0
    class Solution(object):
        def findLongestWord(self, s, d):
            :type s: str
            :type d: List[str]
            :rtype: str
            def match(word, s):
                ind, L = 0, len(word)
                for ch in s:
                    if ch == word[ind]:
                        ind +=1
                        if ind == L:
                            return True
                return False
            d.sort(key=lambda item: (-len(item), item))
            for word in d:
                if match(word, s):
                    return word
            return ''

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.