非递归中序遍历的模板改了一下
class Solution {
public TreeNode kthNode(TreeNode root, int k) {
TreeNode res=null,cur=root;
Stack<TreeNode> stack=new Stack();
while(cur!=null || !stack.empty()){
if(cur!=null){
stack.push(cur);
//System.out.println(cur.val);
cur=cur.left;
}else{
res=stack.pop();
k--;
cur=res.right;
if(k==0)
return res;
}
}
return null;
}
}