We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d6d458e commit f5abbbeCopy full SHA for f5abbbe
word-break/jinah92.py
@@ -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
12
+ return False
13
+
14
+ return dfs(0)
0 commit comments