Golang | Leetcode Golang题解之第112题路径总和

题目:

题解:

Go 复制代码
func hasPathSum(root *TreeNode, sum int) bool {
    if root == nil {
        return false
    }
    if root.Left == nil && root.Right == nil {
        return sum == root.Val
    }
    return hasPathSum(root.Left, sum - root.Val) || hasPathSum(root.Right, sum - root.Val)
}
相关推荐
小年糕是糕手1 小时前
【C++】类和对象(二) -- 构造函数、析构函数
java·c语言·开发语言·数据结构·c++·算法·leetcode
(づど)2 小时前
解决VSCode中安装Go环境Gopls失败的问题
vscode·golang
sheeta19986 小时前
LeetCode 每日一题笔记 日期:2025.11.24 题目:1018. 可被5整除的二进制前缀
笔记·算法·leetcode
橘颂TA14 小时前
【剑斩OFFER】算法的暴力美学——两整数之和
算法·leetcode·职场和发展
Dream it possible!15 小时前
LeetCode 面试经典 150_二叉搜索树_二叉搜索树的最小绝对差(85_530_C++_简单)
c++·leetcode·面试
xxxxxxllllllshi15 小时前
【LeetCode Hot100----14-贪心算法(01-05),包含多种方法,详细思路与代码,让你一篇文章看懂所有!】
java·数据结构·算法·leetcode·贪心算法
wavemap17 小时前
先到先得:免费订阅一年ChatGPT Go会员
开发语言·chatgpt·golang
-森屿安年-18 小时前
LeetCode 283. 移动零
开发语言·c++·算法·leetcode
浮尘笔记18 小时前
Go并发编程核心:Mutex和RWMutex的用法
开发语言·后端·golang
元亓亓亓20 小时前
LeetCode热题100--79. 单词搜索
算法·leetcode·职场和发展