Skip to content

Commit 5b5b459

Browse files
committed
O(n^2) time and O(n) space using BFS
1 parent 85d5b6a commit 5b5b459

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

139. Word Break/139. Word Break.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def wordBreak(self, s: str, wordDict: List[str]) -> bool:
3030
if start not in visited:
3131
for end in range(start+1,len(s)+1):
3232
if s[start:end] in wordDict:
33-
q.append(end)
3433
if end == len(s):
3534
return True
35+
else:
36+
q.append(end)
3637
visited.add(start)
3738
return False

0 commit comments

Comments
 (0)