Участник:DChulkov/Leet2

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/word-break/submissions/

 
class Solution:
    def wordBreak(self, s, wordDict):
        n = len(s)
        p = [True] + [False] * n
        for i in range(1, n+1):
            for j in range(i-1, -1, -1):
                if p[j] and s[j:i] in wordDict:
                    p[i] = True
                    break
        return p[n]