Skip to content

Commit

Permalink
二叉树最大深度 null->NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
IcePigZDB committed Dec 26, 2021
1 parent 40a2906 commit 8c16a79
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions problems/0104.二叉树的最大深度.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int getdepth(treenode* node)
代码如下:
```CPP
if (node == null) return 0;
if (node == NULL) return 0;
```

3. 确定单层递归的逻辑:先求它的左子树的深度,再求的右子树的深度,最后取左右深度最大的数值 再+1 (加1是因为算上当前中间节点)就是目前节点为根节点的树的深度。
Expand All @@ -68,7 +68,7 @@ return depth;
class solution {
public:
int getdepth(treenode* node) {
if (node == null) return 0;
if (node == NULL) return 0;
int leftdepth = getdepth(node->left); // 左
int rightdepth = getdepth(node->right); // 右
int depth = 1 + max(leftdepth, rightdepth); // 中
Expand Down Expand Up @@ -104,7 +104,7 @@ public:
void getdepth(treenode* node, int depth) {
result = depth > result ? depth : result; // 中

if (node->left == null && node->right == null) return ;
if (node->left == NULL && node->right == NULL) return ;

if (node->left) { // 左
depth++; // 深度+1
Expand Down Expand Up @@ -137,7 +137,7 @@ public:
int result;
void getdepth(treenode* node, int depth) {
result = depth > result ? depth : result; // 中
if (node->left == null && node->right == null) return ;
if (node->left == NULL && node->right == NULL) return ;
if (node->left) { // 左
getdepth(node->left, depth + 1);
}
Expand Down Expand Up @@ -173,7 +173,7 @@ c++代码如下:
class solution {
public:
int maxdepth(treenode* root) {
if (root == null) return 0;
if (root == NULL) return 0;
int depth = 0;
queue<treenode*> que;
que.push(root);
Expand Down Expand Up @@ -238,7 +238,7 @@ class solution {
public:
int maxdepth(node* root) {
queue<node*> que;
if (root != null) que.push(root);
if (root != NULL) que.push(root);
int depth = 0;
while (!que.empty()) {
int size = que.size();
Expand Down

0 comments on commit 8c16a79

Please sign in to comment.