mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0139.单词拆分.md
增加:python - 和视频中写法一致(和最上面C++写法一致)
This commit is contained in:
@ -351,7 +351,17 @@ class Solution:
|
||||
dp[j] = dp[j] or (dp[j - len(word)] and word == s[j - len(word):j])
|
||||
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]
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user