package leetcode;

import java.util.Set;

/**
 * https://leetcode.com/problems/word-break/
 */
public class Problem139 {
    public boolean wordBreak(String s, Set<String> dict) {
        // TODO:
        return false;
    }
    
    public static void main(String[] args) {
        Problem139 prob = new Problem139();
        
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.HashSet;%0A
 import j
@@ -211,147 +211,588 @@
     
-// TODO:
+return wordBreak(s, dict, new HashSet%3C%3E());%0A    %7D
 %0A    
+%0A
     
-return false;%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        Problem139 prob = new Problem139();%0A        
+private boolean wordBreak(String s, Set%3CString%3E dict, Set%3CString%3E memo) %7B%0A        for (String d : dict) %7B%0A            if (s.equals(d)) %7B%0A                return true;%0A            %7D%0A            if (memo.contains(s)) %7B%0A                return false;%0A            %7D%0A            if (s.startsWith(d)) %7B%0A                boolean found = wordBreak(s.substring(d.length()), dict, memo);%0A                if (found) %7B%0A                    return true;%0A                %7D%0A            %7D%0A        %7D%0A        memo.add(s);%0A        return false;
 %0A   

Solve problem 139