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)
}
相关推荐
tkevinjd3 小时前
反转链表及其应用(力扣2130)
数据结构·leetcode·链表
程序员烧烤5 小时前
【leetcode刷题007】leetcode116、117
算法·leetcode
Swift社区8 小时前
LeetCode 395 - 至少有 K 个重复字符的最长子串
算法·leetcode·职场和发展
Espresso Macchiato8 小时前
Leetcode 3710. Maximum Partition Factor
leetcode·职场和发展·广度优先遍历·二分法·leetcode hard·leetcode 3710·leetcode双周赛167
巴里巴气8 小时前
第15题 三数之和
数据结构·算法·leetcode
一根甜苦瓜9 小时前
Go语言Slice的一道骚题
开发语言·后端·golang
驰羽9 小时前
[GO]Go语言泛型详解
开发语言·golang·xcode
NPE~9 小时前
[手写系列]Go手写db — — 第五版(实现数据库操作模块)
开发语言·数据库·后端·golang·教程·手写系列·手写数据库
西阳未落9 小时前
LeetCode——双指针(进阶)
c++·算法·leetcode
熬了夜的程序员11 小时前
【LeetCode】69. x 的平方根
开发语言·算法·leetcode·职场和发展·动态规划