class Solution(object):
def wordBreak(self, s, wordDict):
"""
:type s: str
:type wordDict: Set[str]
:rtype: bool
"""
#ok[i] represent whether s[:i] can be built
ok=[True] #ok[0] is always True
for i in range(1,len(s)+1):
ok+=any(ok[j] and s[j:i] in wordDict for j in range(i)),
return ok[-1]
网友评论