[leetcode] Inorder Successor in BST


Inorder Successor in BST

Given a binary search tree and a node in it, find the in-order successor of that node in the BST.

Note: If the given node has no in-order successor in the tree, return null.

o(h) time, o(1) space.

If root->val > p->val, root is a possible successor of p, move to root->left

otherwise do not change successor, move to root->right.

 

 

 

This general solution can find the successor of a binary tree node.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of