# **Leetcode筆記(Inorder Successor in BST)** :::info :information_source: 題目 : Inorder Successor in BST, 類型 : binary search tree , 等級 : medium 日期 : 2023/11/30 ::: ### 嘗試 ```python ``` --- ### **優化** ```python class Solution: def inorderSuccessor(self, root: TreeNode, p: TreeNode) -> Optional[TreeNode]: res = TreeNode(-1) while root: if root.val > p.val: res = root root = root.left else: root = root.right if res.val == -1: return None return res ``` --- **思路** **講解連結** Provided by.