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)
}
相关推荐
平凡但不平庸的码农9 分钟前
Go context 包详解
开发语言·后端·golang
m0_6294947315 分钟前
LeetCode 热题 100-----23.反转链表
数据结构·算法·leetcode·链表
Chase_______1 小时前
LeetCode 1493 & 3634 题解:滑动窗口双指针,从“删一个元素的全1子数组“到“最少移除使数组平衡“
算法·leetcode
悲伤小伞2 小时前
LeetCode 热题 100_4-283. 移动零
算法·leetcode·职场和发展
OYangxf2 小时前
力扣hot100【滑动窗口】
算法·leetcode·职场和发展
Tisfy3 小时前
LeetCode 1914.循环轮转矩阵:大模拟(数组原地轮转) —— 附O(1)空间版本
算法·leetcode·矩阵·大模拟
罗超驿3 小时前
3.快乐数专题学习笔记——双指针法在LeetCode 202题中的应用
java·算法·leetcode·职场和发展
_深海凉_3 小时前
LeetCode热题100-小于 n 的最大数(字节高频题)
算法·leetcode·职场和发展
小雅痞3 小时前
[Java][Leetcode middle] 36. 有效的数独
java·算法·leetcode
北顾笙9803 小时前
day43-数据结构力扣
数据结构·算法·leetcode