# -*- 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 not pNode:
return None
if pNode.right:
cur=pNode.right
while cur:
if cur.left:
cur=cur.left
else:
return cur
else:
cur=pNode
while cur.next and cur.next.left!=cur:
cur=cur.next
return cur.next
我的算法之路29--二叉树的下一个结点
最新推荐文章于 2024-05-29 12:00:00 发布
博客给出了一段Python代码,定义了一个二叉树节点类和一个解决方案类。解决方案类中的GetNext方法用于获取给定节点的下一个节点,代码考虑了节点有右子树和无右子树两种情况,并给出了相应的处理逻辑。
2310

被折叠的 条评论
为什么被折叠?



