From f7988e06dc26ffb93d93f41c8454b4d4504f5828 Mon Sep 17 00:00:00 2001 From: ayao98 <91120769+ayao98@users.noreply.github.com> Date: Fri, 31 Mar 2023 15:50:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Update=200104.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E6=B7=B1=E5=BA=A6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit c++语言部分,函数名和节点命名大小写有错误 --- problems/0104.二叉树的最大深度.md | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index b95e39c8..36578fd3 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -50,7 +50,7 @@ 代码如下: ```CPP -int getdepth(treenode* node) +int getdepth(TreeNode* node) ``` 2. 确定终止条件:如果为空节点的话,就返回0,表示高度为0。 @@ -76,14 +76,14 @@ return depth; ```CPP class solution { public: - int getdepth(treenode* node) { + int getdepth(TreeNode* node) { if (node == NULL) return 0; int leftdepth = getdepth(node->left); // 左 int rightdepth = getdepth(node->right); // 右 int depth = 1 + max(leftdepth, rightdepth); // 中 return depth; } - int maxdepth(treenode* root) { + int maxDepth(TreeNode* root) { return getdepth(root); } }; @@ -93,9 +93,9 @@ public: ```CPP class solution { public: - int maxdepth(treenode* root) { + int maxDepth(TreeNode* root) { if (root == null) return 0; - return 1 + max(maxdepth(root->left), maxdepth(root->right)); + return 1 + max(maxDepth(root->left), maxDepth(root->right)); } }; @@ -110,7 +110,7 @@ public: class solution { public: int result; - void getdepth(treenode* node, int depth) { + void getdepth(TreeNode* node, int depth) { result = depth > result ? depth : result; // 中 if (node->left == NULL && node->right == NULL) return ; @@ -127,7 +127,7 @@ public: } return ; } - int maxdepth(treenode* root) { + int maxDepth(TreeNode* root) { result = 0; if (root == NULL) return result; getdepth(root, 1); @@ -144,7 +144,7 @@ public: class solution { public: int result; - void getdepth(treenode* node, int depth) { + void getdepth(TreeNode* node, int depth) { result = depth > result ? depth : result; // 中 if (node->left == NULL && node->right == NULL) return ; if (node->left) { // 左 @@ -155,7 +155,7 @@ public: } return ; } - int maxdepth(treenode* root) { + int maxDepth(TreeNode* root) { result = 0; if (root == 0) return result; getdepth(root, 1); @@ -182,16 +182,16 @@ c++代码如下: ```CPP class solution { public: - int maxdepth(treenode* root) { + int maxDepth(TreeNode* root) { if (root == NULL) return 0; int depth = 0; - queue que; + queue que; que.push(root); while(!que.empty()) { int size = que.size(); depth++; // 记录深度 for (int i = 0; i < size; i++) { - treenode* node = que.front(); + TreeNode* node = que.front(); que.pop(); if (node->left) que.push(node->left); if (node->right) que.push(node->right); @@ -230,11 +230,11 @@ c++代码: ```CPP class solution { public: - int maxdepth(node* root) { + int maxDepth(Node* root) { if (root == 0) return 0; int depth = 0; for (int i = 0; i < root->children.size(); i++) { - depth = max (depth, maxdepth(root->children[i])); + depth = max (depth, maxDepth(root->children[i])); } return depth + 1; } @@ -247,15 +247,15 @@ public: ```CPP class solution { public: - int maxdepth(node* root) { - queue que; + int maxDepth(Node* root) { + queue que; if (root != NULL) que.push(root); int depth = 0; while (!que.empty()) { int size = que.size(); depth++; // 记录深度 for (int i = 0; i < size; i++) { - node* node = que.front(); + Node* node = que.front(); que.pop(); for (int j = 0; j < node->children.size(); j++) { if (node->children[j]) que.push(node->children[j]); From 34e1b0ab5ce4a839ac9bf40b9e7ceb582fd51119 Mon Sep 17 00:00:00 2001 From: ayao98 <91120769+ayao98@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:48:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Update=200112.=E8=B7=AF=E5=BE=84=E6=80=BB?= =?UTF-8?q?=E5=92=8C.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0112.路径总和.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index 9b6027d1..5958de93 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -250,7 +250,7 @@ private: vector> result; vector path; // 递归函数不需要返回值,因为我们要遍历整个树 - void traversal(treenode* cur, int count) { + void traversal(TreeNode* cur, int count) { if (!cur->left && !cur->right && count == 0) { // 遇到了叶子节点且找到了和为sum的路径 result.push_back(path); return; @@ -276,10 +276,10 @@ private: } public: - vector> pathsum(treenode* root, int sum) { + vector> pathSum(TreeNode* root, int sum) { result.clear(); path.clear(); - if (root == null) return result; + if (root == NULL) return result; path.push_back(root->val); // 把根节点放进路径 traversal(root, sum - root->val); return result;