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)
}
相关推荐
今天_也很困5 小时前
LeetCode 热题100-15.三数之和
数据结构·算法·leetcode
千金裘换酒6 小时前
LeetCode 数组经典题刷题
算法·leetcode·职场和发展
alphaTao7 小时前
LeetCode 每日一题 2026/1/12-2026/1/18
python·算法·leetcode
sin_hielo7 小时前
leetcode 2943
数据结构·算法·leetcode
程序员-King.9 小时前
day134—快慢指针—环形链表(LeetCode-141)
算法·leetcode·链表·快慢指针
Swift社区9 小时前
LeetCode 376 摆动序列
算法·leetcode·职场和发展
且去填词9 小时前
深入理解 GMP 模型:Go 高并发的基石
开发语言·后端·学习·算法·面试·golang·go
a程序小傲10 小时前
京东Java面试被问:多活数据中心的流量调度和数据同步
java·开发语言·面试·职场和发展·golang·边缘计算
Morwit10 小时前
*【力扣hot100】 448. 找到所有数组中消失的数字
数据结构·算法·leetcode
0和1的舞者11 小时前
力扣hot100-链表专题-刷题笔记(二)
笔记·算法·leetcode·链表·职场和发展