-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path139.py
More file actions
executable file
·28 lines (28 loc) · 801 Bytes
/
Copy path139.py
File metadata and controls
executable file
·28 lines (28 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution:
wDict: List[str]
flag: bool
def dfs(self,current,last):
if (self.flag):
return
if (current == ''):
if (self.wDict.get(last) != None):
self.flag = True
return
else:
self.flag = False
return
tmp = last + current[:1]
if (self.wDict.get(last) != None):
self.dfs(current[1:],'')
self.dfs(current[1:],tmp)
else:
self.dfs(current[1:],tmp)
if (self.flag):
return
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
self.wDict = {}
for each in wordDict:
self.wDict[each] = 1
self.flag = False
self.dfs(s,'')
return self.flag