public boolean wordBreak(String s, Set<String> dict) {
if(s.length()==0) return true;
String first = null;
boolean isOk= false;
for(int i=1; i<s.length(); i++){
first = s.substring(0,i);
if(dict.contains(first)){
String remaining = s.substring(i);
isOk = wordBreak(remaining, dict);
if(dict.contains(remaining))
isOk=true;
if(isOk)
return isOk;
}
}
return false;
}
我无法通过此案例的无限循环:“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
执行输入:["a","aa","aaa","aaaa","aaaaa","aaaaaa","aaaaaaaa","aaaaaaaa","aaaaaaaaaa","aaaaaaaaaa"] 谁能帮我指出逻辑错误?谢谢