Problem can be found in [here](https://leetcode.com/problems/inorder-successor-in-bst/!
# Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def inorderSuccessor(root: TreeNode, p: TreeNode) -> Optional[TreeNode]:
successor = None
while root:
if p.val >= root.val:
root = root.right
else:
successor = root
root = root.left
return successor