标签:empty new nbsp ack 数值 pop bsp 中序遍历 tac
TreeNode KthNode(TreeNode pRoot, int k) {
if(count > k || pRoot == null)
return null;
TreeNode p = pRoot;
Stack<TreeNode> stack = new Stack<>();
TreeNode kthNode = null;
stack.push(pRoot);
while(!stack.isEmpty()){
TreeNode tn = stack.peek();
while(tn != null){
tn = tn.left;
stack.push(tn);
}
stack.pop();
if (!stack.isEmpty()) {
tn = stack.pop();
count++;
if (count == k)
kthNode = tn;
stack.push(tn.right);
}
}
return kthNode;
}
标签:empty new nbsp ack 数值 pop bsp 中序遍历 tac
原文地址:https://www.cnblogs.com/MarkLeeBYR/p/9773509.html