Skip to content

Commit 14ff932

Browse files
Merge pull request youngyangyang04#2534 from VoxDai/patch-2
Update 0222.完全二叉树的节点个数.md / Fix Typo
2 parents 56a7c68 + 19b7672 commit 14ff932

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

problems/0222.完全二叉树的节点个数.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@
5454
1. 确定递归函数的参数和返回值:参数就是传入树的根节点,返回就返回以该节点为根节点二叉树的节点数量,所以返回值为int类型。
5555

5656
代码如下:
57-
```
57+
```CPP
5858
int getNodesNum(TreeNode* cur) {
5959
```
6060
6161
2. 确定终止条件:如果为空节点的话,就返回0,表示节点数为0。
6262
6363
代码如下:
6464
65-
```
65+
```CPP
6666
if (cur == NULL) return 0;
6767
```
6868

6969
3. 确定单层递归的逻辑:先求它的左子树的节点数量,再求右子树的节点数量,最后取总和再加一 (加1是因为算上当前中间节点)就是目前节点为根节点的节点数量。
7070

7171
代码如下:
7272

73-
```
73+
```CPP
7474
int leftNum = getNodesNum(cur->left); //
7575
int rightNum = getNodesNum(cur->right); //
7676
int treeNum = leftNum + rightNum + 1; //

0 commit comments

Comments
 (0)