classSolution:defwordBreak(self,s:str,wordDict: List[str]) ->bool: dic =set(wordDict)@lru_cache(None)defdfs(substring): n =len(substring)if n ==0:returnTrue i =0while i < n:if substring[:i +1]in dic anddfs(substring[i +1:]):returnTrue i +=1returnFalsereturndfs(s)