Update 0139.单词拆分.md

增加:python - 和视频中写法一致(和最上面C++写法一致)
This commit is contained in:
ZerenZhang2022
2023-04-09 18:07:43 -04:00
committed by GitHub
parent ba03a17e68
commit 2be03e614d

View File

@ -351,7 +351,17 @@ class Solution:
dp[j] = dp[j] or (dp[j - len(word)] and word == s[j - len(word):j]) dp[j] = dp[j] or (dp[j - len(word)] and word == s[j - len(word):j])
return dp[len(s)] return dp[len(s)]
``` ```
```python
class Solution: # 和视频中写法一致和最上面C++写法一致)
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
dp = [False]*(len(s)+1)
dp[0]=True
for j in range(1,len(s)+1):
for i in range(j):
word = s[i:j]
if word in wordDict and dp[i]: dp[j]=True
return dp[-1]
```