Longest Word in Dictionary through Deleting LeetCode solution in Python
1class Solution:2def findLongestWord(self, s: str, dictionary: list[str]) -> str:3solution = ""4for word in dictionary:5j = 06for i in range(len(s)):7if s[i] == word[j]:8j += 19if j == len(word):10solution = (11word12if len(word) > len(solution)13or len(word) == len(solution)14and word < solution15else solution16)17break18return solution