Concise Morris traversal based solution in Python

  • 0
    class Solution(object):
        def flatten(self, root):
            curr = root
            while curr:
                if curr.left:
                    prev = curr.left
                    while prev.right:
                        prev = prev.right
                    prev.right = curr.right
                    curr.right = curr.left
                    tmp = curr.left; curr.left = None
                    curr = tmp
                    curr = curr.right

Log in to reply

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