更新0129.求根到叶子结点数字之和中,go语言代码无法通过leetcode的语法错误

修改了原本的go代码的错误(原本的go代码无法通过leetcode的题目执行,有语法错误)
This commit is contained in:
SwaggyP
2022-08-19 16:52:06 +08:00
committed by GitHub
parent b7e4c6901f
commit c7c211c30b

View File

@ -250,22 +250,22 @@ Go
```go ```go
func sumNumbers(root *TreeNode) int { func sumNumbers(root *TreeNode) int {
sum = 0 sum := 0
travel(root, root.Val) dfs(root, root.Val, &sum)
return sum return sum
} }
func travel(root *TreeNode, tmpSum int) { func dfs(root *TreeNode, tmpSum int, sum *int) {
if root.Left == nil && root.Right == nil { if root.Left == nil && root.Right == nil {
sum += tmpSum *sum += tmpSum
} else { } else {
if root.Left != nil { if root.Left != nil {
travel(root.Left, tmpSum*10+root.Left.Val) dfs(root.Left, tmpSum*10 + root.Left.Val, sum)
} }
if root.Right != nil { if root.Right != nil {
travel(root.Right, tmpSum*10+root.Right.Val) dfs(root.Right, tmpSum*10 + root.Right.Val, sum)
} }
} }
} }
``` ```