Skip to content

Commit c96e7dd

Browse files
author
root
committed
Added Word Break Leetcode
1 parent 9dc99d9 commit c96e7dd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
3+
dp = [0]*(len(s)+1)
4+
wordDict = set(wordDict)
5+
dp[0]=1
6+
for i in range(1,len(s)+1):
7+
for j in range(i-1,-1,-1):
8+
if dp[j] and s[j:i] in wordDict:
9+
dp[i]=1
10+
break
11+
return dp[-1]
12+

0 commit comments

Comments
 (0)