Python preorder solution


  • 0
    4
    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)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.