We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5f080b5 commit 2b62803Copy full SHA for 2b62803
word-break/prograsshopper.py
@@ -0,0 +1,15 @@
1
+# Time complexity: O(N∗N∗M)
2
+# Space complexity: O(N)
3
+class Solution:
4
+ def wordBreak(self, s: str, wordDict: List[str]) -> bool:
5
+ dp = [False] * (len(s) + 1)
6
+ dp[0] = True
7
+ wordSet = set(wordDict)
8
+
9
+ for i in range(1, len(s) + 1):
10
+ for j in range(0, i):
11
+ if dp[j]:
12
+ if s[j:i] in wordSet:
13
+ dp[i] = True
14
+ break
15
+ return dp[len(s)]
0 commit comments