Recursive solution, which exceeds the time limit.
(s string, wordDict []string)
| 34 | |
| 35 | // Recursive solution, which exceeds the time limit. |
| 36 | func wordBreak0(s string, wordDict []string) bool { |
| 37 | // create a set of words in wordDict for fast lookup |
| 38 | wordDictSet := make(map[string]bool) |
| 39 | for _, w := range wordDict { |
| 40 | wordDictSet[w] = true |
| 41 | } |
| 42 | |
| 43 | return wordBreakHelper(s, wordDictSet, 0) |
| 44 | } |
| 45 | |
| 46 | func wordBreakHelper(s string, wordDictSet map[string]bool, start int) bool { |
| 47 | // if we've reached the start of s, the string has been broken up |