python题解

二叉树的下一个结点

http://www.nowcoder.com/questionTerminal/9023a0c988684a53960365b889ceaf5e

class Solution:
    def GetNext(self, pNode):
        # write code here
        # 此节点有右子树
        if pNode.right:
            temp = pNode.right
            while temp:
                result = temp
                temp = temp.left
            return result
        # 此节点没有右子树
        while pNode:
            if pNode.next:
                if pNode.next.left == pNode:
                    return pNode.next
                pNode = pNode.next
            else:
                return None
全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 13:05
点赞 评论 收藏
分享
06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
评论
8
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务