mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Fix the code of preorder_traversal_iii_compact
This commit is contained in:
@@ -19,6 +19,7 @@ func preOrderIII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {
|
||||
if int(root.Val) == 7 {
|
||||
// 记录解
|
||||
*res = append(*res, *path)
|
||||
*path = (*path)[:len(*path)-1]
|
||||
return
|
||||
}
|
||||
preOrderIII(root.Left, res, path)
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestPreorderTraversalIIICompact(t *testing.T) {
|
||||
res := make([][]*TreeNode, 0)
|
||||
preOrderIII(root, &res, &path)
|
||||
|
||||
fmt.Println("\n输出所有根节点到节点 7 的路径,且路径中不包含值为 3 的节点")
|
||||
fmt.Println("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点,仅包含一个值为 7 的节点")
|
||||
for _, path := range res {
|
||||
for _, node := range path {
|
||||
fmt.Printf("%v ", node.Val)
|
||||
@@ -81,7 +81,7 @@ func TestPreorderTraversalIIITemplate(t *testing.T) {
|
||||
choices = append(choices, root)
|
||||
backtrackIII(&state, &choices, &res)
|
||||
|
||||
fmt.Println("\n输出所有根节点到节点 7 的路径,且路径中不包含值为 3 的节点")
|
||||
fmt.Println("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点,仅包含一个值为 7 的节点")
|
||||
for _, path := range res {
|
||||
for _, node := range path {
|
||||
fmt.Printf("%v ", node.Val)
|
||||
|
||||
Reference in New Issue
Block a user