@@ -48,7 +48,7 @@ int getdepth(treenode* node)
4848
4949代码如下:
5050```CPP
51- if (node == null ) return 0;
51+ if (node == NULL ) return 0;
5252```
5353
54543 . 确定单层递归的逻辑:先求它的左子树的深度,再求的右子树的深度,最后取左右深度最大的数值 再+1 (加1是因为算上当前中间节点)就是目前节点为根节点的树的深度。
@@ -68,7 +68,7 @@ return depth;
6868class solution {
6969public:
7070 int getdepth(treenode* node) {
71- if (node == null ) return 0;
71+ if (node == NULL ) return 0;
7272 int leftdepth = getdepth(node->left); // 左
7373 int rightdepth = getdepth(node->right); // 右
7474 int depth = 1 + max(leftdepth, rightdepth); // 中
@@ -104,7 +104,7 @@ public:
104104 void getdepth(treenode* node, int depth) {
105105 result = depth > result ? depth : result; // 中
106106
107- if (node->left == null && node->right == null ) return ;
107+ if (node->left == NULL && node->right == NULL ) return ;
108108
109109 if (node->left) { // 左
110110 depth++; // 深度+1
@@ -137,7 +137,7 @@ public:
137137 int result;
138138 void getdepth(treenode* node, int depth) {
139139 result = depth > result ? depth : result; // 中
140- if (node->left == null && node->right == null ) return ;
140+ if (node->left == NULL && node->right == NULL ) return ;
141141 if (node->left) { // 左
142142 getdepth(node->left, depth + 1);
143143 }
@@ -173,7 +173,7 @@ c++代码如下:
173173class solution {
174174public:
175175 int maxdepth(treenode* root) {
176- if (root == null ) return 0;
176+ if (root == NULL ) return 0;
177177 int depth = 0;
178178 queue<treenode*> que;
179179 que.push(root);
@@ -238,7 +238,7 @@ class solution {
238238public:
239239 int maxdepth(node* root) {
240240 queue<node*> que;
241- if (root != null ) que.push(root);
241+ if (root != NULL ) que.push(root);
242242 int depth = 0;
243243 while (!que.empty()) {
244244 int size = que.size();
0 commit comments