思路:如果在j处可以被分词,那么在j+1-i处在可以继续分割。
class Solution {
public boolean wordBreak(String s, List<String> wordDict) {
boolean f[]=new boolean [s.length()+1];
f[0]=true;
for(int i=1; i <= s.length(); i++){
for(int j=0; j < i; j++){
if(f[j] && wordDict.contains(s.substring(j, i))){
f[i] = true;
break;
}
}
}
return f[s.length()];
}
}