December_day_3
Leetcode December Challege Day 3 Link to heading
Solution to the question
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def increasingBST(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if root == None:
return None
left = self.increasingBST(root.left)
if left == None:
head = root
else:
head = left
while left and left.right != None:
left = left.right
left.right = root
root.left = None
right = self.increasingBST(root.right)
root.right = right
return head