We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1bc9a15 + a149a4b commit 06a64cdCopy full SHA for 06a64cd
go/0112-path-sum.go
@@ -0,0 +1,25 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * type TreeNode struct {
4
+ * Val int
5
+ * Left *TreeNode
6
+ * Right *TreeNode
7
+ * }
8
+ */
9
+
10
+func hasPathSum(root *TreeNode, targetSum int) bool {
11
+ if root == nil {
12
+ return false
13
+ }
14
+ if isChild(root) && targetSum == root.Val {
15
+ return true
16
17
+ if hasPathSum(root.Left, targetSum-root.Val) || hasPathSum(root.Right, targetSum-root.Val) {
18
19
20
21
+}
22
23
+func isChild(node *TreeNode) bool {
24
+ return node.Left == nil && node.Right == nil
25
0 commit comments