class Solution: # @param s, a string # @param dict, a set of string # @return a boolean def wordBreak(self, s, dict): n=len(s) dp=[False for i in range(n)] for i in range(1,n+1): if s[:i] in dict: dp[i-1]=True for j in range(1,i): if dp[j-1] and s[j:i] in dict: dp[i-1]=True return dp[n-1] if n>0 else '' in dict
Thursday, September 18, 2014
Leetcode: Word Break @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment