You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hello-algo/codes/go/chapter_backtracking/preorder_traversal_i_compac...

23 lines
428 B

// File: preorder_traversal_i_compact.go
// Created Time: 2023-05-09
// Author: Reanon (793584285@qq.com)
package chapter_backtracking
import (
. "github.com/krahets/hello-algo/pkg"
)
/* 前序遍历:例题一 */
func preOrderI(root *TreeNode, res *[]*TreeNode) {
if root == nil {
return
}
if int(root.Val) == 7 {
// 记录解
*res = append(*res, root)
}
preOrderI(root.Left, res)
preOrderI(root.Right, res)
}