牛客网链接
# -*- coding:utf-8 -*-
# class TreeLinkNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
# self.next = None
class Solution:
def GetNext(self, pNode):
# write code here
#若该节点为空,则空;
if pNode==None :return None
#若该节点有右子树,则应为右子树的最左子节点;
if pNode.right:
tmp=pNode.right
while tmp.left:
tmp=tmp.left
return tmp
else:
if pNode.next == None : return None
if pNode.next.left == pNode : return pNode.next
if pNode.next.next.left == pNode.next : return pNode.next.next