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]);