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 6d1adcd commit 93b4acfCopy full SHA for 93b4acf
word-break/evan.py
@@ -0,0 +1,17 @@
1
+from typing import List
2
+
3
4
+class Solution:
5
+ def wordBreak(self, s: str, wordDict: List[str]) -> bool:
6
+ dp = [False] * (len(s) + 1)
7
+ dp[0] = True
8
9
+ for i in range(1, len(s) + 1):
10
+ for j in range(i):
11
+ # If the substring s[:j] is breakable and the substring s[j:i] is in the wordSet,
12
+ # then the substring s[:i] is breakable
13
+ if dp[j] and s[j:i] in wordDict:
14
+ dp[i] = True
15
+ break
16
17
+ return dp[len(s)]
0 commit comments