美文网首页
139. Word Break

139. Word Break

作者: 阿团相信梦想都能实现 | 来源:发表于2016-12-26 10:25 被阅读0次
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]

相关文章

网友评论

      本文标题:139. Word Break

      本文链接:https://www.haomeiwen.com/subject/ufkjvttx.html