Skip to content

Commit 997903b

Browse files
committed
solve : word break
1 parent f407e6e commit 997903b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

word-break/samthekorean.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)