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)
}
相关推荐
苏琢玉13 小时前
从零开始做 Go 项目:我的目录设计分享
开发语言·后端·golang
ByNotD0g13 小时前
Golang开发项目学习
学习·微服务·云原生·golang
沐雨风栉13 小时前
被局域网困住的文件?cpolar让 Go File 随时随地能用
运维·服务器·开发语言·数据库·后端·缓存·golang
野蛮人6号13 小时前
力扣热题100道前84道,内容和力扣官方稍有不同,记录了本人的一些独特的解法
java·算法·leetcode·职场和发展
玖剹13 小时前
floodfill算法题目(二)
c语言·c++·算法·leetcode·深度优先·dfs·深度优先遍历
卿雪13 小时前
MySQL【基础】篇:什么是MySQL、主键和外键、三大范式、DDL、DML、DDL、DCL...
java·服务器·开发语言·数据库·后端·mysql·golang
圣保罗的大教堂13 小时前
leetcode 2872. 可以被 K 整除连通块的最大数目 困难
leetcode
学学学无无止境13 小时前
力扣-颠倒二进制位
leetcode
sin_hielo13 小时前
leetcode 2141
数据结构·算法·leetcode
杀死那个蝈坦14 小时前
Redis 多级缓存:架构设计、核心问题与落地实践
开发语言·spring·青少年编程·golang·kotlin·maven·lua