class Solution {
public boolean wordBreak(String s, List<String> wordDict) {
Set<String> set = new HashSet<>(wordDict);
//dp[i]表示以i结尾的字符串是否符合题目要求,符合为true
boolean[] dp = new boolean[s.length()+1];
dp[0]=true;
for(int i=1;i<dp.length;i++){
for(int j=0;j<i;j++){
//如果 i ---j 之间可以组成任何一个单词,并且dp[i]=true,则dp[j]符合题目要求。
//状态转移方程
if(dp[j]==true && set.contains(s.substring(j,i))){
dp[i] = true;
break;
}
}
}
return dp[dp.length-1];
}
}