/*
public class TreeLinkNode {
int val;
TreeLinkNode left = null;
TreeLinkNode right = null;
TreeLinkNode next = null;
TreeLinkNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public TreeLinkNode GetNext(TreeLinkNode pNode)
{
TreeLinkNode current = null;
if (pNode.right != null){
current = pNode.right;
while (current.left != null){current = current.left;}
return current;
}
current = pNode.next;
if (current == null) return null;
if (current.left == pNode){
return current;
}
while (current.next != null){
if (current == current.next.left){
return current.next;
}
current = current.next;
}
return null;
}
}
[剑指offer]二叉树的下一个节点
最新推荐文章于 2025-05-25 22:30:28 发布