/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func hasPathSum(root *TreeNode, targetSum int) bool {
if nil == root {
return false
}
if root.Left == nil && root.Right == nil {
return root.Val == targetSum
}
return hasPathSum(root.Left, targetSum - root.Val) || hasPathSum(root.Right, targetSum - root.Val)
}
leetcode二叉树路径总和递归实现
最新推荐文章于 2024-07-30 21:02:05 发布
博客围绕二叉树与算法展开,虽未给出具体内容,但从标签可知涉及二叉树相关算法,可能会结合 leetcode 题目进行探讨,为信息技术领域中数据结构与算法方面的知识。


441

被折叠的 条评论
为什么被折叠?



