Skip to content

Commit

Permalink
Word Break
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliehan23 committed Feb 17, 2014
1 parent f109e78 commit 5f3e1ce
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions wordBreak.py
@@ -0,0 +1,24 @@
class Solution:
# @param s, a string
# @param dict, a set of string
# @return a boolean
def wordBreak(self, s, dict):
if len(s) == 0:
return False
ss = len(s)
mp = [[False for i in range(ss)] for j in range(ss)]

for i in range(ss):
for j in range(i, ss):
if s[i:j+1] in dict:
mp[i][j] = True


for i in range(ss):
for j in range(i, ss):
for k in range(i, j):
if mp[i][j]==False:
mp[i][j] = mp[i][k] and mp[k+1][j]

return mp[0][ss-1]

0 comments on commit 5f3e1ce

Please sign in to comment.