MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

DP/WordBreak.py:56–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55"""
56class Solution(object):
57 def wordBreak(self, s, wordDict):
58 """
59 :type s: str
60 :type wordDict: List[str]
61 :rtype: bool
62 """
63
64 dp = [True] + [False] * len(s)
65
66 for i in range(len(s)):
67 for j in range(i+1):
68 if dp[j] == True:
69 for x in wordDict:
70 if x == s[j:j+len(x)]:
71 dp[j+len(x)] = True
72
73 return dp[-1]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected