mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -252,6 +252,23 @@ class Solution {
|
|||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
|
||||||
|
```python3
|
||||||
|
class Solution:
|
||||||
|
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 word in wordDict:
|
||||||
|
if j >= len(word):
|
||||||
|
dp[j] = dp[j] or (dp[j - len(word)] and word == s[j - len(word):j])
|
||||||
|
return dp[len(s)]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
```Go
|
```Go
|
||||||
|
Reference in New Issue
Block a user