接著說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()];
}
}