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 分钟前
匿名函数与闭包(Anonymous Functions and Closures)-《Go语言实战指南》原创
后端·golang
I AM_SUN19 分钟前
98. 验证二叉搜索树
数据结构·c++·算法·leetcode
言之。1 小时前
Go 语言中接口类型转换为具体类型
开发语言·后端·golang
{⌐■_■}2 小时前
【gRPC】HTTP/2协议,HTTP/1.x中线头阻塞问题由来,及HTTP/2中的解决方案,RPC、Protobuf、HTTP/2 的关系及核心知识点汇总
网络·网络协议·计算机网络·http·rpc·golang
珊瑚里的鱼3 小时前
【滑动窗口】LeetCode 1658题解 | 将 x 减到 0 的最小操作数
开发语言·c++·笔记·算法·leetcode·stl
进击的小白菜3 小时前
用Java实现单词搜索(LeetCode 79)——回溯算法详解
java·算法·leetcode
珂朵莉MM3 小时前
2024 睿抗机器人开发者大赛CAIP-编程技能赛-专科组(国赛)解题报告 | 珂学家
开发语言·人工智能·算法·leetcode·职场和发展·深度优先·图论
圈圈编码5 小时前
LeetCode Hot100刷题——轮转数组
java·算法·leetcode·职场和发展
运维-大白同学5 小时前
go-中间件的使用
中间件·golang·xcode
北上ing12 小时前
算法练习:19.JZ29 顺时针打印矩阵
算法·leetcode·矩阵