# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def Convert(self, pRootOfTree):
# write code here
if not pRootOfTree:
return None
root=self.dp(pRootOfTree)
while root.left:
root=root.left
return root
def dp(self,root):
if not root:
return None
cur=root
if cur.left:
l=self.dp(root.left)
while l.right:
l=l.right
cur.left=l
l.right=cur
if cur.right:
r=self.dp(root.right)
while r.left:
r=r.left
cur.right=r
r.left=cur
return cur