139. Word Break
class Solution { public boolean wordBreak(String s, List<String> wordDict) { boolean[] dp=new boolean[s.length()+1]; dp[0]=true; for(int i=0;i<s.length();i++) for(String w:wordDict) if(i+1-w.length()>=0&&w.equals(s.substring(i+1-w.length(),i+1))) dp[i+1]=dp[i+1]||dp[i+1-w.length()]; return dp[s.length()]; } }