Golang | Leetcode Golang题解之第235题二叉搜索树的最近公共祖先

题目:

题解:

func lowestCommonAncestor(root, p, q *TreeNode) (ancestor *TreeNode) {
    ancestor = root
    for {
        if p.Val < ancestor.Val && q.Val < ancestor.Val {
            ancestor = ancestor.Left
        } else if p.Val > ancestor.Val && q.Val > ancestor.Val {
            ancestor = ancestor.Right
        } else {
            return
        }
    }
}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 08:14:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 08:14:01       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 08:14:01       58 阅读
  4. Python语言-面向对象

    2024-07-15 08:14:01       69 阅读

热门阅读

  1. Mybatis

    Mybatis

    2024-07-15 08:14:01      20 阅读
  2. AI学习指南机器学习篇-高斯混合模型

    2024-07-15 08:14:01       22 阅读
  3. 使用 Dubbo 的 XML 配置

    2024-07-15 08:14:01       20 阅读
  4. 阿里新开源GPU版本的FunASR安装避坑

    2024-07-15 08:14:01       25 阅读
  5. 简单理解Lua 协程(coroutine)

    2024-07-15 08:14:01       19 阅读
  6. DangerWind-RPC-framework---七、序列化算法

    2024-07-15 08:14:01       22 阅读
  7. Android RecyclerView

    2024-07-15 08:14:01       18 阅读
  8. 在Ubuntu 14.04上安装和保护phpMyAdmin的方法

    2024-07-15 08:14:01       23 阅读