Skip to content

Instantly share code, notes, and snippets.

View fudigit's full-sized avatar

fudigit

  • Rice University
  • Austin, TX
View GitHub Profile
@fudigit
fudigit / 107.Word_Break.py
Created December 17, 2019 01:50
107.Word_Break.py
#v1. DFS + Memoization,需要加大recursion limit
import sys
sys.setrecursionlimit(100000000)
class Solution:
def wordBreak(self, s, dict):
memo = {} # index: false
max_len = -1
for word in dict:
max_len = max(max_len, len(word))
ans = self.dfs(s, 0, dict, memo, max_len)