Longest Word in Dictionary through Deleting LeetCode solution in Python

1
class Solution:
2
def findLongestWord(self, s: str, dictionary: list[str]) -> str:
3
solution = ""
4
for word in dictionary:
5
j = 0
6
for i in range(len(s)):
7
if s[i] == word[j]:
8
j += 1
9
if j == len(word):
10
solution = (
11
word
12
if len(word) > len(solution)
13
or len(word) == len(solution)
14
and word < solution
15
else solution
16
)
17
break
18
return solution

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0