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)
}
相关推荐
谢亮_vipxieliang9 分钟前
Go Gin 中间件与参数验证:从入门到实战
中间件·golang·gin
All for pursuit.2 小时前
【动态规划-6】96.不同的二叉搜索树
数据结构·c++·算法·leetcode·动态规划
All for pursuit.3 小时前
【并查集-2】399.除法求值
数据结构·c++·算法·leetcode
Nil2085 小时前
leetcode 416分割等和子集
算法·leetcode·职场和发展
y1su7 小时前
Leetcode 二分模板
java·数据结构·算法·leetcode·排序算法
Pniubi8 小时前
力扣55跳跃游戏(贪心)
算法·leetcode·游戏
microrain9 小时前
同一个值,四个名字,四套口径:SagooIoT 属性上报链路的 Canonical 收敛
物联网·golang·开源·sagooiot
CoderYanger10 小时前
A.每日一题:856. 括号的分数
java·程序人生·算法·leetcode·面试·职场和发展·学习方法
tachibana211 小时前
Golang 中数组和切片的区别?
开发语言·后端·golang·数组·切片
All for pursuit.11 小时前
【动态规划-8】152.乘积最大子数组
数据结构·c++·算法·leetcode·动态规划