标签:
纯dp
class Solution: # @param s, a string # @param dict, a set of string # @return a boolean def wordBreak(self, s, dict): length = len(s) dp = [False]*(length + 1) dp[0] = True i = 1 while i < length+1: j = i-1 while j >= 0: cur = s[j:i] if dp[j] and cur in dict: dp[i] = True break j -= 1 i += 1 return dp[length]
标签:
原文地址:http://www.cnblogs.com/dapanshe/p/4666190.html