更新代码块

This commit is contained in:
youngyangyang04
2021-08-10 22:20:48 +08:00
parent c7c34dd824
commit 8a2d42013c
192 changed files with 552 additions and 552 deletions

View File

@@ -21,7 +21,7 @@
100.相同的树的递归代码如下:
```C++
```CPP
class Solution {
public:
bool compare(TreeNode* left, TreeNode* right) {
@@ -48,7 +48,7 @@ public:
100.相同的树,精简之后代码如下:
```C++
```CPP
class Solution {
public:
bool compare(TreeNode* left, TreeNode* right) {
@@ -67,7 +67,7 @@ public:
100.相同的树,迭代法代码如下:
```C++
```CPP
class Solution {
public:
@@ -109,7 +109,7 @@ public:
**而根节点的高度就是二叉树的最大深度**,所以本题中我们通过后序求的根节点高度来求的二叉树最大深度,所以[二叉树:看看这些树的最大深度](https://mp.weixin.qq.com/s/guKwV-gSNbA1CcbvkMtHBg)中使用的是后序遍历。
本题当然也可以使用前序,代码如下:(**充分表现出求深度回溯的过程**)
```C++
```CPP
class Solution {
public:
int result;
@@ -143,7 +143,7 @@ public:
注意以上代码是为了把细节体现出来,简化一下代码如下:
```C++
```CPP
class Solution {
public:
int result;
@@ -223,12 +223,12 @@ public:
文中我明确的说了:**回溯就隐藏在traversal(cur->left, path + "->", result);中的 path + "->"。 每次函数调用完path依然是没有加上"->" 的,这就是回溯了。**
如果还不理解的话,可以把
```C++
```CPP
traversal(cur->left, path + "->", result);
```
改成
```C++
```CPP
string tmp = path + "->";
traversal(cur->left, tmp, result);
```