@@ -0,0 +1,981 @@
+public class Solution %7B%0A    public boolean wordBreak(String s, Set%3CString%3E wordDict) %7B%0A        if(s == null %7C%7C s.length() == 0)%7B%0A            return true;%0A        %7D%0A        int len = s.length();%0A        int maxWordLen = maxLength(wordDict);%0A        boolean%5B%5D able = new boolean%5Blen + 1%5D;%0A        Arrays.fill(able, false);%0A        able%5B0%5D = true;%0A        %0A        for(int i = 1; i %3C= len; i ++)%7B%0A            for(int j = 1; j %3C= maxWordLen && j %3C= i; j ++)%7B%0A                if(!able%5Bi - j%5D)%7B%0A                    continue;%0A                %7D%0A                String word = s.substring(i - j, i);%0A                if(wordDict.contains(word))%7B%0A                    able%5Bi%5D = true;%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A        return able%5Blen%5D;%0A    %7D%0A    %0A    private int maxLength(Set%3CString%3E wordDict)%7B%0A        int maxLen = 0;%0A        for(String word : wordDict)%7B%0A            maxLen = Math.max(word.length(), maxLen);%0A        %7D%0A        return maxLen;%0A    %7D%0A%7D

Q139 Word Break