Skip to content

Commit bfa58a6

Browse files
committed
solve: wordBreak
1 parent 7d72661 commit bfa58a6

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

word-break/daehyun99.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+
pos = set()
4+
pos.add(0)
5+
len_s = len(s)
6+
7+
while len(pos) > 0 :
8+
l = pos.pop()
9+
for word in wordDict:
10+
if s[l:].startswith(word):
11+
pos.add(l+len(word))
12+
if l == len_s:
13+
return True
14+
return False

0 commit comments

Comments
 (0)