码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode140

时间:2019-03-08 17:13:43      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:date   lse   start   object   list   dbr   ==   ida   span   

 1 class Solution(object):
 2     def wordBreak(self, s, wordDict):
 3         """
 4         :type s: str
 5         :type wordDict: Set[str]
 6         :rtype: List[str]
 7         """
 8         return findWords(0, len(s), s, wordDict, {})
 9 
10 def findWords(start, end, s, wordDict, cache):
11     if start in cache:
12         return cache[start]
13     cache[start] = []
14     candidate = ‘‘
15     current = start
16     while current < end:
17         candidate += s[current]
18         current += 1
19         if candidate in wordDict:
20             if current == end:
21                 cache[start].append(candidate)
22             else:
23                 for x in findWords(current, end, s, wordDict, cache):
24                     cache[start].append(candidate +   + x)
25     return cache[start]

 

leetcode140

标签:date   lse   start   object   list   dbr   ==   ida   span   

原文地址:https://www.cnblogs.com/asenyang/p/10496351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!