mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0226.翻转二叉树.md
This commit is contained in:
@ -257,7 +257,7 @@ public:
|
|||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
|
|
||||||
Java
|
### Java
|
||||||
```Java
|
```Java
|
||||||
//DFS递归
|
//DFS递归
|
||||||
class Solution {
|
class Solution {
|
||||||
@ -308,7 +308,7 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Python
|
### Python
|
||||||
|
|
||||||
递归法:前序遍历:
|
递归法:前序遍历:
|
||||||
```python
|
```python
|
||||||
@ -360,7 +360,7 @@ class Solution:
|
|||||||
return root
|
return root
|
||||||
```
|
```
|
||||||
|
|
||||||
Go
|
### Go
|
||||||
|
|
||||||
递归版本的前序遍历
|
递归版本的前序遍历
|
||||||
```Go
|
```Go
|
||||||
@ -469,7 +469,7 @@ func invertTree(root *TreeNode) *TreeNode {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
### JavaScript
|
||||||
|
|
||||||
使用递归版本的前序遍历
|
使用递归版本的前序遍历
|
||||||
```javascript
|
```javascript
|
||||||
@ -550,7 +550,7 @@ var invertTree = function(root) {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
递归法:
|
递归法:
|
||||||
|
|
||||||
@ -677,7 +677,7 @@ function invertTree(root: TreeNode | null): TreeNode | null {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
C
|
### C
|
||||||
|
|
||||||
递归法
|
递归法
|
||||||
```c
|
```c
|
||||||
@ -724,7 +724,7 @@ struct TreeNode* invertTree(struct TreeNode* root){
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Swift:
|
### Swift:
|
||||||
```swift
|
```swift
|
||||||
// 前序遍历-递归
|
// 前序遍历-递归
|
||||||
func invertTree(_ root: TreeNode?) -> TreeNode? {
|
func invertTree(_ root: TreeNode?) -> TreeNode? {
|
||||||
@ -762,7 +762,6 @@ func invertTree1(_ root: TreeNode?) -> TreeNode? {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Swift
|
|
||||||
|
|
||||||
深度优先递归。
|
深度优先递归。
|
||||||
|
|
||||||
@ -856,7 +855,7 @@ object Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
rust
|
### rust
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl Solution {
|
impl Solution {
|
||||||
|
Reference in New Issue
Block a user