Skip to content

Commit 1384fbf

Browse files
Solve : Word Break
1 parent 13aa8e6 commit 1384fbf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

word-break/printjin-gmailcom.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def wordBreak(self, s, wordDict):
3+
wordSet = set(wordDict)
4+
dp = [False] * (len(s) + 1)
5+
dp[0] = True
6+
7+
for i in range(1, len(s) + 1):
8+
for j in range(i):
9+
if dp[j] and s[j:i] in wordSet:
10+
dp[i] = True
11+
break
12+
13+
return dp[len(s)]

0 commit comments

Comments
 (0)