MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / wordBreak

Method wordBreak

Python/word-break-1.py:9–24  ·  view source on GitHub ↗
(self, s: str, wordDict: List[str])

Source from the content-addressed store, hash-verified

7
8class Solution:
9 def wordBreak(self, s: str, wordDict: List[str]) -> bool:
10 dict=set(wordDict)
11 dp = {}
12 def helper(s,dict,dp):
13 if s in dp:
14 return dp[s]
15 l=len(s)
16 if l==0:
17 return True
18 for i in range(l):
19 if s[:i+1] in dict and helper(s[i+1:],dict,dp):
20 dp[s[:i+1]] = True
21 return True
22 dp[s] = False
23 return False
24 return helper(s,dict,dp)
25
26
27# Method 2 : Tabulation

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected