题解 | #二叉搜索树与双向链表#
二叉搜索树与双向链表
http://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5
python递归指针,非列表
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
#
#
# @param pRootOfTree TreeNode类
# @return TreeNode类
#
class Solution:
def __init__(self):
self.head = TreeNode(0)
self.cur = self.head
def Convert(self , pRootOfTree ):
if not pRootOfTree:
return
self.midorder(pRootOfTree)
cur1 = self.head.right
self.head.right.left = None
return cur1
def midorder(self, node):
if node == None:
return
self.midorder(node.left)
self.cur.right = TreeNode(node.val)
self.cur.right.left = self.cur
self.cur = self.cur.right
self.midorder(node.right)