285. 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. The successor of a node p is the node with the smallest key greater than p.val.

def inorderSuccessor(self, root: 'TreeNode', p: 'TreeNode') -> 'TreeNode': 
    result,cur = None,root 
    while cur: 
        if cur.val > p.val: 
            result = cur 
            cur = cur.left 
        else: 
            cur = cur.right 
    return result