Skip to content

Commit 5de30ec

Browse files
committed
feat: Word Break
1 parent ec75cf3 commit 5de30ec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

word-break/HodaeSsi.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 시간복잡도 : O(n^2)
2+
# 공간복잡도 : 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+
8+
for i in range(1, len(s) + 1):
9+
for j in range(i):
10+
if dp[j] and s[j:i] in wordDict:
11+
dp[i] = True
12+
break
13+
14+
return dp[-1]
15+

0 commit comments

Comments
 (0)