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 f407e6e commit 997903bCopy full SHA for 997903b
word-break/samthekorean.py
@@ -0,0 +1,12 @@
1
+# TC : O(s^2*w)
2
+# SC : O(s)
3
+class Solution:
4
+ def wordBreak(self, s: str, wordDict: List[str]) -> bool:
5
+ dp = [True] + [False] * len(s)
6
+ for n in range(1, len(s) + 1):
7
+ for word in wordDict:
8
+ if s[n - len(word) : n] == word:
9
+ dp[n] = dp[n - len(word)]
10
+ if dp[n]:
11
+ break
12
+ return dp[-1]
0 commit comments