Comments (3)
func recordSolution(state *[]*TreeNode, res *[][]*TreeNode) {
- *res = append(*res, *state)
+ copy_state := make([]*TreeNode, len(*state))
+ copy(copy_state, *state)
+ *res = append(*res, copy_state)
找到了一种解决办法, 添加到res之前 复制一个slice ,要不以后修改state,会影响到 res的内容
复制一个新的slice 就行了,
不知道大家有没有什么好办法, 我是抛砖引玉了
from hello-algo.
好像 preOrderIII 函数的输出也是1 7 5 7
└─[$] go test -run=TestPreorderTraversalIIICompact [15:48:36]
初始化二叉树
/———7
/———3
| \———6
———1
| /———5
\———7
\———4
\———7
输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点
1 7
1 7 5 7
PASS
ok github.com/krahets/hello-algo/chapter_backtracking
from hello-algo.
@xtccc Thanks! Fixed in #1087 by @Reanon. Please check if the bug solved.
from hello-algo.
Related Issues (20)
- 在2.3时间复杂度中建议补充时间复杂度类型根号阶 HOT 1
- Python 数组代码修改 HOT 1
- 对于有多个参数的函数时间及空间复杂度怎么表示 HOT 1
- 请问怎样取消邮件?别人的评论会一致给我发邮件 HOT 1
- 在线文档中出现多余的转义符号 HOT 2
- 新增部分高级数据结构讲解
- 建议加个buy you a coffee HOT 1
- 希望切換語言時能保持在相同章節 HOT 5
- Array and List in Rust HOT 2
- 请问以后会有基础篇的讲解更新吗 HOT 1
- 图的章节里希望补充:最小生成树相关知识
- 文章挺好的,但是网页太卡,毫无缓存 HOT 1
- codes/c/chapter_stack_and_queue/array_stack.c 代码有误 HOT 1
- hello-algo/codes/c/chapter_hashing /hash_map_open_addressing.c运行出现段错误 HOT 1
- 11.5快速排序 HOT 2
- 15.1 贪心算法例子 coin_change_greedy.js HOT 1
- PDF in Languages Other Than Simplified Chinese HOT 1
- this project is amazing, could be amazing a english version. HOT 1
- graph_adjacency_list_test.c 有误 HOT 2
- 使用C语言的二叉树层序遍历的算法优化(通过链表实现伪队列) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hello-algo.