deno.land / x / masx200_leetcode_test@10.6.5 / successor-lcci / index.ts
1234567891011121314151617181920212223242526import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
function inorderSuccessor( root: TreeNode | null, p: TreeNode | null,): TreeNode | null { if (!root) { return null; } if (!p) { return null; }
if (root.val <= p.val) { return inorderSuccessor(root.right, p); } else { const ans = inorderSuccessor(root.left, p); if (ans) { return ans; } else { return root; } }}export default inorderSuccessor;
Version Info