mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
Update
This commit is contained in:
@@ -69,15 +69,15 @@ if (cur->left == NULL && cur->right == NULL) {
|
||||
|
||||
再来看一下终止处理的逻辑。
|
||||
|
||||
这里使用vector<int> 结构path来记录路径,所以要把vector<int> 结构的path转为string格式,再把这个string 放进 result里。
|
||||
这里使用`vector<int>` 结构path来记录路径,所以要把`vector<int>` 结构的path转为string格式,再把这个string 放进 result里。
|
||||
|
||||
**那么为什么使用了vector<int> 结构来记录路径呢?** 因为在下面处理单层递归逻辑的时候,要做回溯,使用vector方便来做回溯。
|
||||
**那么为什么使用了`vector<int>` 结构来记录路径呢?** 因为在下面处理单层递归逻辑的时候,要做回溯,使用vector方便来做回溯。
|
||||
|
||||
可能有的同学问了,我看有些人的代码也没有回溯啊。
|
||||
|
||||
**其实是有回溯的,只不过隐藏在函数调用时的参数赋值里**,下文我还会提到。
|
||||
|
||||
这里我们先使用vector<int>结构的path容器来记录路径,那么终止处理逻辑如下:
|
||||
这里我们先使用`vector<int>`结构的path容器来记录路径,那么终止处理逻辑如下:
|
||||
|
||||
```CPP
|
||||
if (cur->left == NULL && cur->right == NULL) { // 遇到叶子节点
|
||||
|
||||
Reference in New Issue
Block a user