From 8c16a79ea406385fd1520d14016a3373e145c473 Mon Sep 17 00:00:00 2001 From: db <39407623+IcePigZDB@users.noreply.github.com> Date: Sun, 26 Dec 2021 22:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E6=B7=B1=E5=BA=A6=20null->NULL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0104.二叉树的最大深度.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index 82a82fd5..e0cf2b63 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -48,7 +48,7 @@ int getdepth(treenode* node) 代码如下: ```CPP -if (node == null) return 0; +if (node == NULL) return 0; ``` 3. 确定单层递归的逻辑:先求它的左子树的深度,再求的右子树的深度,最后取左右深度最大的数值 再+1 (加1是因为算上当前中间节点)就是目前节点为根节点的树的深度。 @@ -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); // 中 @@ -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 @@ -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); } @@ -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 que; que.push(root); @@ -238,7 +238,7 @@ class solution { public: int maxdepth(node* root) { queue que; - if (root != null) que.push(root); + if (root != NULL) que.push(root); int depth = 0; while (!que.empty()) { int size = que.size();