老师你好,211号问题,在搜索时,想使用非递归的方式可以吗,自己写了一个,但是提交时还是有的测试用例不成功。希望老师做出指正,谢谢老师。代码如下:
public boolean search(String word) {
Node cur = root;
for (int i = 0; i < word.length(); i++) {
char c = word.charAt(i);
if ('.' != c){
if (cur.next.get(c) == null){
return false;
}
cur = cur.next.get(c);
}else{
char nc = ' ';
for (char nextchar : cur.next.keySet()){
if (cur.next.get(nextchar) == null){
return false;
}else{
nc = nextchar;
}
}
cur = cur.next.get(nc);
}
}
if (cur != null){
return cur.isWord;
}
return false;
}