题解 | #二叉树的下一个结点#
二叉树的下一个结点
http://www.nowcoder.com/practice/9023a0c988684a53960365b889ceaf5e
public class Solution {
    public TreeLinkNode GetNext(TreeLinkNode pNode) {
       if(pNode.right!=null)
        return findLeft(pNode.right);
        
        while(pNode.next!=null)
        {
            TreeLinkNode parent=pNode.next;
            if(parent.left==pNode)//是左孩子
                return parent;
            //是右孩子
            pNode=parent;
        }
        return null;
    }
    TreeLinkNode findLeft(TreeLinkNode root)
    {
        if(root.left==null) return root;
        return findLeft(root.left);
    }
} 
查看18道真题和解析