mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-25 01:32:21 +08:00
Update
This commit is contained in:
@ -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:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
```
|
||||
|
||||
为什么这个中序就是可以的呢,因为这是用栈来遍历,而不是靠指针来遍历,避免了递归法中翻转了两次的情况,大家可以画图理解一下,这里有点意思的。
|
||||
|
Reference in New Issue
Block a user