Skip to content

Commit c606ecc

Browse files
Merge pull request youngyangyang04#1995 from ayao98/master
更新 0104.二叉树的最大深度 0113.路径综合 C++函数命名有错误
2 parents d9888ab + fa4f4dd commit c606ecc

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

problems/0104.二叉树的最大深度.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
代码如下:
5252
```CPP
53-
int getdepth(treenode* node)
53+
int getdepth(TreeNode* node)
5454
```
5555
5656
2. 确定终止条件:如果为空节点的话,就返回0,表示高度为0。
@@ -76,14 +76,14 @@ return depth;
7676
```CPP
7777
class solution {
7878
public:
79-
int getdepth(treenode* node) {
79+
int getdepth(TreeNode* node) {
8080
if (node == NULL) return 0;
8181
int leftdepth = getdepth(node->left); // 左
8282
int rightdepth = getdepth(node->right); // 右
8383
int depth = 1 + max(leftdepth, rightdepth); // 中
8484
return depth;
8585
}
86-
int maxdepth(treenode* root) {
86+
int maxDepth(TreeNode* root) {
8787
return getdepth(root);
8888
}
8989
};
@@ -93,9 +93,9 @@ public:
9393
```CPP
9494
class solution {
9595
public:
96-
int maxdepth(treenode* root) {
96+
int maxDepth(TreeNode* root) {
9797
if (root == null) return 0;
98-
return 1 + max(maxdepth(root->left), maxdepth(root->right));
98+
return 1 + max(maxDepth(root->left), maxDepth(root->right));
9999
}
100100
};
101101
@@ -110,7 +110,7 @@ public:
110110
class solution {
111111
public:
112112
int result;
113-
void getdepth(treenode* node, int depth) {
113+
void getdepth(TreeNode* node, int depth) {
114114
result = depth > result ? depth : result; // 中
115115

116116
if (node->left == NULL && node->right == NULL) return ;
@@ -127,7 +127,7 @@ public:
127127
}
128128
return ;
129129
}
130-
int maxdepth(treenode* root) {
130+
int maxDepth(TreeNode* root) {
131131
result = 0;
132132
if (root == NULL) return result;
133133
getdepth(root, 1);
@@ -144,7 +144,7 @@ public:
144144
class solution {
145145
public:
146146
int result;
147-
void getdepth(treenode* node, int depth) {
147+
void getdepth(TreeNode* node, int depth) {
148148
result = depth > result ? depth : result; // 中
149149
if (node->left == NULL && node->right == NULL) return ;
150150
if (node->left) { // 左
@@ -155,7 +155,7 @@ public:
155155
}
156156
return ;
157157
}
158-
int maxdepth(treenode* root) {
158+
int maxDepth(TreeNode* root) {
159159
result = 0;
160160
if (root == 0) return result;
161161
getdepth(root, 1);
@@ -182,16 +182,16 @@ c++代码如下:
182182
```CPP
183183
class solution {
184184
public:
185-
int maxdepth(treenode* root) {
185+
int maxDepth(TreeNode* root) {
186186
if (root == NULL) return 0;
187187
int depth = 0;
188-
queue<treenode*> que;
188+
queue<TreeNode*> que;
189189
que.push(root);
190190
while(!que.empty()) {
191191
int size = que.size();
192192
depth++; // 记录深度
193193
for (int i = 0; i < size; i++) {
194-
treenode* node = que.front();
194+
TreeNode* node = que.front();
195195
que.pop();
196196
if (node->left) que.push(node->left);
197197
if (node->right) que.push(node->right);
@@ -230,11 +230,11 @@ c++代码:
230230
```CPP
231231
class solution {
232232
public:
233-
int maxdepth(node* root) {
233+
int maxDepth(Node* root) {
234234
if (root == 0) return 0;
235235
int depth = 0;
236236
for (int i = 0; i < root->children.size(); i++) {
237-
depth = max (depth, maxdepth(root->children[i]));
237+
depth = max (depth, maxDepth(root->children[i]));
238238
}
239239
return depth + 1;
240240
}
@@ -247,15 +247,15 @@ public:
247247
```CPP
248248
class solution {
249249
public:
250-
int maxdepth(node* root) {
251-
queue<node*> que;
250+
int maxDepth(Node* root) {
251+
queue<Node*> que;
252252
if (root != NULL) que.push(root);
253253
int depth = 0;
254254
while (!que.empty()) {
255255
int size = que.size();
256256
depth++; // 记录深度
257257
for (int i = 0; i < size; i++) {
258-
node* node = que.front();
258+
Node* node = que.front();
259259
que.pop();
260260
for (int j = 0; j < node->children.size(); j++) {
261261
if (node->children[j]) que.push(node->children[j]);

problems/0112.路径总和.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private:
250250
vector<vector<int>> result;
251251
vector<int> path;
252252
// 递归函数不需要返回值,因为我们要遍历整个树
253-
void traversal(treenode* cur, int count) {
253+
void traversal(TreeNode* cur, int count) {
254254
if (!cur->left && !cur->right && count == 0) { // 遇到了叶子节点且找到了和为sum的路径
255255
result.push_back(path);
256256
return;
@@ -276,10 +276,10 @@ private:
276276
}
277277

278278
public:
279-
vector<vector<int>> pathsum(treenode* root, int sum) {
279+
vector<vector<int>> pathSum(TreeNode* root, int sum) {
280280
result.clear();
281281
path.clear();
282-
if (root == null) return result;
282+
if (root == NULL) return result;
283283
path.push_back(root->val); // 把根节点放进路径
284284
traversal(root, sum - root->val);
285285
return result;

0 commit comments

Comments
 (0)