114. 二叉树展开为链表
程序员文章站
2024-03-26 13:59:11
...
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def flatten(self, root):
"""
:type root: TreeNode
:rtype: None Do not return anything, modify root in-place instead.
"""
while root:
if root.left:
most_node = root.left
while most_node.right:
most_node = most_node.right
most_node.right = root.right
root.right = root.left
root.left = None
root = root.right
上一篇: 114. 二叉树展开为链表
下一篇: matplotlib画图总结