Skip to content

Commit

Permalink
feat: Word Break
Browse files Browse the repository at this point in the history
  • Loading branch information
HodaeSsi committed Jan 11, 2025
1 parent ec75cf3 commit 5de30ec
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions word-break/HodaeSsi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 시간복잡도 : O(n^2)
# 공간복잡도 : O(n)
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
dp = [False] * (len(s) + 1)
dp[0] = True

for i in range(1, len(s) + 1):
for j in range(i):
if dp[j] and s[j:i] in wordDict:
dp[i] = True
break

return dp[-1]

0 comments on commit 5de30ec

Please sign in to comment.