mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 11:16:28 +08:00
a6b3f72826
* feat(go/backtracking): add go code * feat(backtracking): add n_queens in go * feat(backtracking): add /preorder_traversal_i_compact in go * feat(backtracking): add /preorder_traversal_ii_compact in go * feat(backtracking): add /preorder_traversal_ii_template in go * feat(backtracking): add preorder_traversal_iii_compact in go * feat(backtracking): add preorder_traversal_test in go * feat(backtracking): add permutations_i in go * feat(backtracking): add permutations_ii in go * feat(backtracking): add permutation_test in go * feat(backtracking): fix bug in go * Update permutations_i.go --------- Co-authored-by: Yudong Jin <krahets@163.com>
22 lines
428 B
Go
22 lines
428 B
Go
// 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)
|
|
}
|