We simply store the node values one by one from the tree using the in-order tree traversal and once we are done we can simply generate a tree in the required configuration
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = NoneclassSolution(object):definorderTraversal(self,root):""" https://leetcode.com/problems/binary-tree-inorder-traversal/description/ :type root: TreeNode :rtype: List[int] """ res, stack = [], []whileTrue:while root: stack.append(root) root = root.leftifnot stack:return res node = stack.pop() res.append(node.val) root = node.rightdefincreasingBST(self,root):""" :type root: TreeNode :rtype: TreeNode """ l = self.inorderTraversal(root) rootCopy =TreeNode(l[0]) traverse = rootCopyfor i in l[1:]: traverse.left =None traverse.right =TreeNode(i) traverse = traverse.rightreturn rootCopy