赞
踩
目录
139.单词拆分
139. 单词拆分 - 力扣(LeetCode)https://leetcode.cn/problems/word-break/
- class Solution:
- def wordBreak(self, s: str, wordDict: List[str]) -> bool:
- n = len(s)
- dp = [False]*(n+1)
- dp[0] = True
- for i in range(n+1):
- for item in wordDict:
- m = len(item)
- if i>=m:
- dp[i] =dp[i] or (dp[i-m] and s[i-m:i]==item)
- return dp[-1]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。