Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions word-break/prograsshopper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Time complexity: O(N∗N∗M)
# Space complexity: O(N)
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
dp = [False] * (len(s) + 1)
dp[0] = True
wordSet = set(wordDict)

for i in range(1, len(s) + 1):
for j in range(0, i):
if dp[j]:
if s[j:i] in wordSet:
dp[i] = True
break
return dp[len(s)]