Skip to content

Commit aad265a

Browse files
aQuaaQua
aQua
authored and
aQua
committed
437 wrong answer
1 parent 77d0d28 commit aad265a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Algorithms/0437.path-sum-iii/path-sum-iii.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ package Problem0437
33
import (
44
"github.com/aQuaYi/LeetCode-in-Golang/kit"
55
)
6+
67
type TreeNode = kit.TreeNode
78

89
func pathSum(root *TreeNode, sum int) int {
9-
res :=0
10+
res := 0
11+
if root == nil {
12+
return res
13+
}
14+
15+
newSum := sum - root.Val
16+
if newSum == 0 {
17+
res++
18+
return 1 + pathSum(root.Left, sum) + pathSum(root.Right, sum)
19+
}
1020

11-
return res
21+
return pathSum(root.Left, sum) +
22+
pathSum(root.Right, sum) +
23+
pathSum(root.Left, newSum) +
24+
pathSum(root.Right, newSum)
1225
}

Algorithms/0437.path-sum-iii/path-sum-iii_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ func Test_Problem0437(t *testing.T) {
2020
}{
2121

2222
{
23-
[]int{10, 5, 3, 3, -2, 2, 1, -3, 11},
24-
[]int{3, 3, -2, 5, 2, 1, 10, -3, 11},
23+
[]int{8, 5, 3, 5, -2, 2, 1, -3, 11},
24+
[]int{5, 3, -2, 5, 2, 1, 8, -3, 11},
2525
8,
26-
3,
26+
5,
2727
},
2828

2929
// 可以多个 testcase

0 commit comments

Comments
 (0)