Leetcode 139 Solution
This article provides solution to leetcode question 139 (word-break)
Access this page by simply typing in "lcs 139" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/word-break
Solution
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
dp = [False] * (len(s) + 1)
dp[0] = True
for i in range(len(s)):
if dp[i] == False:
continue
for word in wordDict:
if word == s[i:len(word) + i]:
dp[len(word) + i] = True
return dp[len(s)]