```
public boolean wordBreak(String s, Set<String> wordDict) {
int len = s.length();
int[] dp = new int[len+1];
dp[0] = 1;
for(int i = 1; i <= len; i++) {
for(int j = i-1; j >= 0; j--) {
if(dp[j] != 1) continue;
String target = s.substring(j,i);
if(wordDict.contains(target)) {
dp[i] = 1;
break;
}
}
}
return dp[len]==1;
}
```