This commit is contained in:
youngyangyang04
2021-07-27 17:47:31 +08:00
parent 36e9e22a6e
commit 1c601fe722
30 changed files with 3975 additions and 61 deletions

View File

@ -152,7 +152,7 @@ public:
如果非要使用递归中序的方式写,也可以,如下代码就可以避免节点左右孩子翻转两次的情况:
```
```C++
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
@ -171,7 +171,7 @@ public:
代码如下:
```
```C++
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
@ -197,7 +197,6 @@ public:
}
};
```
为什么这个中序就是可以的呢,因为这是用栈来遍历,而不是靠指针来遍历,避免了递归法中翻转了两次的情况,大家可以画图理解一下,这里有点意思的。