接着说dic可能很大怎么办,建立字典树,要会写
public class Solution {
public boolean wordBreak(String s, Set<String> wordDict) {
boolean[] res=new boolean[s.length()+1];
res[0]=true;
for(int i=1;i<=s.length();i++){
for(int j=0;j<i;j++){
if(res[j]&&wordDict.contains(s.substring(j,i))){
res[i]=true;
break;
}
}
}
return res[s.length()];
}
}