题目链接
lintcode915BST中序遍历前驱结点
思路同915 ,只是last更新条件变成root.val>p.val
class Solution:
"""
@param: root: The root of the BST.
@param: p: You need find the successor node of p.
@return: Successor of p.
"""
def inorderSuccessor(self, root, p):
# write your code here
last = None
while root:
if root.val>p.val:
last = root
root = root.left
else:
root =root.right
return last