Leetcode 933 Solution

This article provides solution to leetcode question 933 (increasing-order-search-tree)

https://leetcode.com/problems/increasing-order-search-tree

Solution

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def reorder(self, root):
        if not root:
            return

        self.reorder(root.left)

        root.left = None
        self.cur.right = root
        self.cur = root

        self.reorder(root.right)


    def increasingBST(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        ans = self.cur = TreeNode(0)
        self.reorder(root)
        return ans.right