Merge pull request #2476 from qingfenggoat/patch-1

Update 0104.二叉树的最大深度中关于solution大小写问题.md
This commit is contained in:
程序员Carl
2024-04-15 09:43:06 +08:00
committed by GitHub

View File

@ -77,7 +77,7 @@ return depth;
所以整体c++代码如下: 所以整体c++代码如下:
```CPP ```CPP
class solution { class Solution {
public: public:
int getdepth(TreeNode* node) { int getdepth(TreeNode* node) {
if (node == NULL) return 0; if (node == NULL) return 0;
@ -94,7 +94,7 @@ public:
代码精简之后c++代码如下: 代码精简之后c++代码如下:
```CPP ```CPP
class solution { class Solution {
public: public:
int maxDepth(TreeNode* root) { int maxDepth(TreeNode* root) {
if (root == null) return 0; if (root == null) return 0;
@ -110,7 +110,7 @@ public:
本题当然也可以使用前序,代码如下:(**充分表现出求深度回溯的过程**) 本题当然也可以使用前序,代码如下:(**充分表现出求深度回溯的过程**)
```CPP ```CPP
class solution { class Solution {
public: public:
int result; int result;
void getdepth(TreeNode* node, int depth) { void getdepth(TreeNode* node, int depth) {
@ -144,7 +144,7 @@ public:
注意以上代码是为了把细节体现出来,简化一下代码如下: 注意以上代码是为了把细节体现出来,简化一下代码如下:
```CPP ```CPP
class solution { class Solution {
public: public:
int result; int result;
void getdepth(TreeNode* node, int depth) { void getdepth(TreeNode* node, int depth) {
@ -183,7 +183,7 @@ public:
c++代码如下: c++代码如下:
```CPP ```CPP
class solution { class Solution {
public: public:
int maxDepth(TreeNode* root) { int maxDepth(TreeNode* root) {
if (root == NULL) return 0; if (root == NULL) return 0;
@ -232,7 +232,7 @@ public:
c++代码: c++代码:
```CPP ```CPP
class solution { class Solution {
public: public:
int maxDepth(Node* root) { int maxDepth(Node* root) {
if (root == 0) return 0; if (root == 0) return 0;
@ -249,7 +249,7 @@ public:
依然是层序遍历,代码如下: 依然是层序遍历,代码如下:
```CPP ```CPP
class solution { class Solution {
public: public:
int maxDepth(Node* root) { int maxDepth(Node* root) {
queue<Node*> que; queue<Node*> que;
@ -278,7 +278,7 @@ public:
104.二叉树的最大深度 104.二叉树的最大深度
```java ```java
class solution { class Solution {
/** /**
* 递归法 * 递归法
*/ */
@ -319,7 +319,7 @@ class Solution {
``` ```
```java ```java
class solution { class Solution {
/** /**
* 迭代法,使用层序遍历 * 迭代法,使用层序遍历
*/ */
@ -369,7 +369,7 @@ class Solution {
``` ```
```java ```java
class solution { class Solution {
/** /**
* 迭代法,使用层序遍历 * 迭代法,使用层序遍历
*/ */
@ -402,7 +402,7 @@ class solution {
递归法: 递归法:
```python ```python
class solution: class Solution:
def maxdepth(self, root: treenode) -> int: def maxdepth(self, root: treenode) -> int:
return self.getdepth(root) return self.getdepth(root)
@ -417,7 +417,7 @@ class solution:
递归法:精简代码 递归法:精简代码
```python ```python
class solution: class Solution:
def maxdepth(self, root: treenode) -> int: def maxdepth(self, root: treenode) -> int:
if not root: if not root:
return 0 return 0