思路
分情况,总体上存在右子节点与没有,没有右子节点,分多种。
代码
public class Solution {
public TreeLinkNode GetNext(TreeLinkNode pNode){
if(pNode==null){return null;}
if(pNode.right!=null){
pNode=pNode.right;
while(pNode.left!=null){
pNode=pNode.left;
}
return pNode;
}else{//没有右子节点
if(pNode.next==null){return null;}
if(pNode==pNode.next.left){
return pNode.next;
}else{
if(pNode.next.next==null || pNode.next==pNode.next.next.right){
return null;
}else{
return pNode.next.next;
}
}
}
}
}
京公网安备 11010502036488号