inorder successor in bst

🏠

https://leetcode.com/problems/inorder-successor-in-bst/submissions/

This is a totally acceptable solution to this problem. The in-order traversal of a

 1class Solution:
 2    def inorderSuccessor(self, root: 'TreeNode', p: 'TreeNode') -> 'TreeNode':
 3        def dfs(n):
 4            if n:
 5                dfs(n.left)
 6                vals.append(n)
 7                dfs(n.right)
 8        vals = []
 9        dfs(root)
10        if vals:
11            return next(iter([x for x in vals if x.val > p.val]), None)