给你一个字符串 s 和一个字符串列表 wordDict 作为字典,判定 s 是否可以由空格拆分为一个或多个在字典中出现的单词。
说明:拆分时可以重复使用字典中的单词。
。
class Solution {
public boolean wordBreak(String s, List<String> wordDict) {
boolean [] vaild=new boolean[s.length()+1];
vaild[0]=true;
for(int i=0;i<=s.length();i++){
for(int j=0;j<i;j++){
if(wordDict.contains(s.substring(j,i)) && vaild[j]){
vaild[i]=true;
}
}
}
return vaild[s.length()];
}
}
453

被折叠的 条评论
为什么被折叠?



