class Solution {
public boolean wordBreak(String s, List<String> wordDict) {
boolean[] dp=new boolean[s.length()+1];
dp[0]=true;//初始状态
for(int i=1;i<=s.length();i++){
for(int j=0;j<i;j++){
//j前面可以满足,同时i,j字符串也满足。(j,i左闭右开)
if(dp[j]&&wordDict.contains(s.substring(j,i))){
dp[i]=true;
break;
}
}
}
return dp[s.length()];
}
}