【二叉树】二叉树的下一个结点

2019-08-26  本文已影响0人  一个想当大佬的菜鸡
# -*- 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):
        if pNode.right:
            p = pNode.right
            while p.left:
                p = p.left
            return p
        if pNode.next and pNode.next.left == pNode:
            return pNode.next
        father = pNode.next
        while father and father.left != pNode:
            pNode = father
            father = father.next
        return father
上一篇下一篇

猜你喜欢

热点阅读