Skip to content

Commit

Permalink
Merge branch 'master' of github.com:youngyangyang04/leetcode-master
Browse files Browse the repository at this point in the history
  • Loading branch information
youngyangyang04 committed May 17, 2024
2 parents 7ab1e2d + b69b852 commit 259d197
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions problems/0257.二叉树的所有路径.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@

要传入根节点,记录每一条路径的path,和存放结果集的result,这里递归不需要返回值,代码如下:

```
```CPP
void traversal(TreeNode* cur, vector<int>& path, vector<string>& result)
```
2. 确定递归终止条件
在写递归的时候都习惯了这么写:
```
```CPP
if (cur == NULL) {
终止处理逻辑
}
Expand All @@ -59,7 +59,7 @@ if (cur == NULL) {
**那么什么时候算是找到了叶子节点?** 是当 cur不为空,其左右孩子都为空的时候,就找到叶子节点。

所以本题的终止条件是:
```
```CPP
if (cur->left == NULL && cur->right == NULL) {
终止处理逻辑
}
Expand Down Expand Up @@ -102,7 +102,7 @@ if (cur->left == NULL && cur->right == NULL) { // 遇到叶子节点

所以递归前要加上判断语句,下面要递归的节点是否为空,如下

```
```CPP
if (cur->left) {
traversal(cur->left, path, result);
}
Expand Down

0 comments on commit 259d197

Please sign in to comment.