forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd886f0
commit 14126f0
Showing
1 changed file
with
9 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### 545.Boundary-of-Binary-Tree | ||
|
||
需要分别写子函数遍历左边界、底部叶子节点、右边界。 | ||
|
||
对于左边界,注意题目要求,当根节点没有左子树时,左边界就只是根。所以,遍历左边界的函数其实可以从root->left开始。同理,遍历右边界的函数可以从root->right开始。左边界、右边界求完后,都要各自pop_back(),为叶子节点数组腾出重复的节点位置。 | ||
|
||
另外,遍历底部叶子节点,需要注意仅有根节点的情况,这时不算有叶子节点。 | ||
|
||
最终结果就是:根 + 左边界(弹出最后一个)+ 所有叶子节点(不包括根)+ 右边界的反序(弹出最后一个)。 |