题解 | #牛的奶量统计#
牛的奶量统计
https://www.nowcoder.com/practice/213c039668804add9513bbee31370248?tpId=354&tqId=10591582&ru=/exam/oj/ta&qru=/ta/interview-202-top/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D354
知识点:
dfs
解题思路:
一边dfs,一边将target-cur.Val
语言:
Golang
package main
/*
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @param targetSum int整型
* @return bool布尔型
*/
func hasPathSum( root *TreeNode , targetSum int ) bool {
// write code here
if root == nil{
return false
}
if root.Val == targetSum{
return true
}
return hasPathSum(root.Left, targetSum-root.Val)||hasPathSum(root.Right, targetSum-root.Val)
}
三奇智元机器人科技有限公司公司福利 84人发布