A relative concise Python code


  • 2
    P
    class Solution:
        # @param root, a tree node
        # @return nothing, do it in place
        def flatten1(self, root):
            if not root:
                return
            self.flatten(root.left)
            self.flatten(root.right)
            if root.left:
                temp = root.right
                root.right = root.left
                root.left = None
                while root.right:
                    root = root.right
                root.right = temp

Log in to reply
 

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