139. Word Break

2016-12-26  本文已影响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]
上一篇 下一篇

猜你喜欢

热点阅读