From e9341c51b5399b7d6be517219a6911e51a368238 Mon Sep 17 00:00:00 2001 From: Reanon <793584285@qq.com> Date: Sun, 18 Feb 2024 18:37:07 +0800 Subject: [PATCH] fix(go): record slice array result, fixed #1075 (#1087) --- codes/go/chapter_backtracking/preorder_traversal_iii_compact.go | 2 +- .../go/chapter_backtracking/preorder_traversal_iii_template.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/go/chapter_backtracking/preorder_traversal_iii_compact.go b/codes/go/chapter_backtracking/preorder_traversal_iii_compact.go index a94c3a937..f9ce23bb8 100644 --- a/codes/go/chapter_backtracking/preorder_traversal_iii_compact.go +++ b/codes/go/chapter_backtracking/preorder_traversal_iii_compact.go @@ -18,7 +18,7 @@ func preOrderIII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) { *path = append(*path, root) if root.Val.(int) == 7 { // 记录解 - *res = append(*res, *path) + *res = append(*res, append([]*TreeNode{}, *path...)) } preOrderIII(root.Left, res, path) preOrderIII(root.Right, res, path) diff --git a/codes/go/chapter_backtracking/preorder_traversal_iii_template.go b/codes/go/chapter_backtracking/preorder_traversal_iii_template.go index fed494bc7..b7901df47 100644 --- a/codes/go/chapter_backtracking/preorder_traversal_iii_template.go +++ b/codes/go/chapter_backtracking/preorder_traversal_iii_template.go @@ -15,7 +15,7 @@ func isSolution(state *[]*TreeNode) bool { /* 记录解 */ func recordSolution(state *[]*TreeNode, res *[][]*TreeNode) { - *res = append(*res, *state) + *res = append(*res, append([]*TreeNode{}, *state...)) } /* 判断在当前状态下,该选择是否合法 */