2024-02-25发表2024-02-25更新LeetCode每日一题1 分钟读完 (大约117个字)235. 二叉搜索树的最近公共祖先二叉搜索树的最近公共祖先 难度: medium 原始链接: https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-search-tree 标签: 一次遍历 解法一: 一次遍历go1234567891011121314151617181920/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { if p.Val > q.Val { return lowestCommonAncestor(root, q, p) } if root.Val < p.Val { return lowestCommonAncestor(root.Right, q, p) } else if root.Val > q.Val { return lowestCommonAncestor(root.Left, q, p) } return root}235. 二叉搜索树的最近公共祖先https://wuhunyu.top/leetcode/2024/02/lowest-common-ancestor-of-a-binary-search-tree/index.html作者wuhunyu发布于2024-02-25更新于2024-02-25许可协议#一次遍历