#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param s string字符串
# @param dic string字符串一维数组
# @return string字符串一维数组
#
class Solution:
# 返回该字符串的切片索引列表
def indexstr(self, s: str, dic: List[str]) -> List[int]:
lenth = len(s)
res = []
for i in range(lenth):
if s[:i + 1] in dic:
res.append(i)
return res
def recur(self, s: str, dic: List[str], tmpstr: str, lout: list ,lenth :int):
index = self.indexstr(s, dic)
lenth = len(s)
curstr = tmpstr
if s == '':
str.strip(tmpstr)
lout.append(tmpstr)
return
if index == []:
return
for i in index:
if len(s) == lenth:
tmpstr = curstr
if tmpstr == '' :
tmpstr = s[:i + 1]
else :
tmpstr = tmpstr + ' ' + s[:i + 1]
self.recur(s[i + 1:], dic, tmpstr, lout ,lenth)
def wordDiv(self, s: str, dic: List[str]) -> List[str]:
# write code here
res = []
index = self.indexstr(s, dic)
if index == []:
return []
tmpstr = ''
lenth = len(s)
self.recur(s, dic, tmpstr, res,lenth)
return res