右旋一次之后有多高

👁️ 0 人浏览 💬 0 人评论 ❤️ 添加收藏

一棵往左歪的小树(17 的左边挂 15,15 的左边挂 13),右旋一次。运行下面这段程序:

class ANode:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

def height(node):
    if node is None:
        return 0
    return 1 + max(height(node.left), height(node.right))

def left_chain():
    root = ANode(17)
    root.left = ANode(15)
    root.left.left = ANode(13)
    return root

root = left_chain()
new_root = root.left
root.left = new_root.right
new_root.right = root
print(height(new_root))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论