8-line simple recursive Python solution

  • 1
    class Solution(object):
        def flatten(self, root):
            :type root: TreeNode
            :rtype: void Do not return anything, modify root in-place instead.
            if root:
                node = root.left
                if node:
                    while node.right:
                        node = node.right
                    root.left, root.right, node.right = None, root.left, root.right

Log in to reply

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