相当于吧rightMovingChunk的root端一点点增加上去
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
rightMovingChunk = None
def flatten(self, root):
"""
:type root: TreeNode
:rtype: void Do not return anything, modify root in-place instead.
"""
if not root: return
self.flatten(root.right)
self.flatten(root.left)
root.right = self.rightMovingChunk
root.left = None
self.rightMovingChunk = root
网友评论