美文网首页
【二叉树】二叉树的下一个结点

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

作者: 一个想当大佬的菜鸡 | 来源:发表于2019-08-26 11:28 被阅读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
    

    相关文章

      网友评论

          本文标题:【二叉树】二叉树的下一个结点

          本文链接:https://www.haomeiwen.com/subject/ccdrectx.html