美文网首页
114. Flatten Binary Tree to Link

114. Flatten Binary Tree to Link

作者: GoDeep | 来源:发表于2018-04-27 16:17 被阅读0次
    image.png

    相当于吧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
    

    相关文章

      网友评论

          本文标题:114. Flatten Binary Tree to Link

          本文链接:https://www.haomeiwen.com/subject/hhfilftx.html