Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2800728

Browse files
author
sejineer
committedMay 1, 2025·
word-break solution
1 parent bff5b2f commit 2800728

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎word-break/sejineer.py

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

0 commit comments

Comments
 (0)
Please sign in to comment.