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)
}
相关推荐
小武~17 小时前
Leetcode 每日一题C 语言版 -- 45 jump game ii
c语言·算法·leetcode
leoufung21 小时前
用 DFS 拓扑排序吃透 LeetCode 210:Course Schedule II
算法·leetcode·深度优先
Swift社区1 天前
LeetCode 443. 压缩字符串
leetcode·职场和发展·蓝桥杯
ada7_1 天前
LeetCode(python)——543.二叉树的直径
数据结构·python·算法·leetcode·职场和发展
sprintzer1 天前
11.26-12.05力扣栈刷题
算法·leetcode·职场和发展
sin_hielo1 天前
leetcode 3578
数据结构·算法·leetcode
前端小白在前进1 天前
力扣刷题:无重复字符的最长子串
算法·leetcode·职场和发展
卿雪1 天前
Redis 线程模型:Redis为什么这么快?Redis为什么引入多线程?
java·数据库·redis·sql·mysql·缓存·golang
好易学·数据结构1 天前
可视化图解算法72:斐波那契数列
数据结构·算法·leetcode·动态规划·力扣·牛客网
CoderYanger1 天前
动态规划算法-子数组、子串系列(数组中连续的一段):21.乘积最大子数组
开发语言·算法·leetcode·职场和发展·动态规划·1024程序员节