114 Flatten Binary Tree to Linked List

114 Flatten Binary Tree to Linked List 

这道题就是Preorder的稍微变种, 记住 pre 的节点就好

class Solution:
    def __init__(self):
        self.pre = TreeNode("dummy")
    
    def flatten(self, root):
        if root == None:
            return
        tmp = root.right
        self.pre.right = root
        self.pre.left = None
        self.pre = root
        self.flatten(root.left)
        self.flatten(tmp)

 

posted @ 2015-07-20 06:43  dapanshe  阅读(114)  评论(0编辑  收藏  举报