This code is failing for the input "a", ["a"], but this code succeeds when I test it locally, any ideas (this is in reference to 139. Word Break)?
class Solution(object):
memo = {}
def wordBreak(self, s, wordDict):
"""
:type s: str
:type wordDict: List[str]
:rtype: bool
"""
wordDictSet = set()
for word in wordDict:
wordDictSet.add(word)
return self.wordBreakHelper(s, wordDictSet)
def wordBreakHelper(self, s, wordDictSet):
if len(s) == 0:
return True
elif s in self.memo:
return self.memo[s]
for i in range(len(s)):
if s[:i+1] in wordDictSet and self.wordBreakHelper(s[i+1:], wordDictSet):
self.memo[s] = True
return True
self.memo[s] = False
return False
```