Skip to content

Commit f5abbbe

Browse files
committed
feat: week5 문제풀이 (271)
1 parent d6d458e commit f5abbbe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

word-break/jinah92.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# O(2^s*w) times, O(s) space
2+
class Solution:
3+
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
4+
@cache
5+
def dfs(start):
6+
if start == len(s):
7+
return True
8+
for word in wordDict:
9+
if s[start:start+len(word)] == word:
10+
if dfs(start+len(word)):
11+
return True
12+
return False
13+
14+
return dfs(0)

0 commit comments

Comments
 (0)