class Solution:
def Convert(self , pRootOfTree ):
# write code here
if not pRootOfTree:
return
self.result = []
self.midOrder(pRootOfTree)
for i in range(1, len(self.result)):
self.result[i].left = self.result[i-1]
self.result[i-1].right = self.result[i]
return self.result[0]
def midOrder(self, p): # 无论是先序、中序还是后序,递归出口都在头部
if not p: return
self.midOrder(p.left)
self.result.append(p)
self.midOrder(p.right)