中级农民
- 积分
- 118
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2013-6-22
- 最后登录
- 1970-1-1
|
多谢面经- class Solution(object):
- def wordBreak(self, s, wordDict):
- """
- :type s: str
- :type wordDict: Set[str]
- :rtype: bool
- """. 1point3acres
- dp = [False]*len(s)
- for i in range(len(s)):
- for j in range(i,len(s)):
- if i==0 and s[i:j+1] in wordDict:
- dp[j] = True
- elif dp[i-1]==True and s[i:j+1] in wordDict:
- dp[j] = True
- return dp[-1]
复制代码
.1point3acres
- class Solution(object):
- def wordBreak(self, s, wordDict):
- """
- :type s: str
- :type wordDict: Set[str]
- :rtype: bool
. 1point 3acres - """. 1point 3acres
- dp = [False]*(len(s)+1)
- dp[0]=True
- for i in range(len(s)+1):. check 1point3acres for more.
- for w in wordDict:. Waral dи,
- l = len(w)
.. - if l<=i and s[i-l:i]==w:
- dp[i] = dp[i-l] or dp[i]
- return dp[-1]
复制代码 |
|