blob: da66748f4c6ee1aaa1f0f7d1faa58a66cf902c45 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package main
import "fmt"
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func invertTree(root *TreeNode) *TreeNode {
var invert func(root *TreeNode)
invert = func(root *TreeNode) {
if root == nil {
return
}
root.Left, root.Right = root.Right, root.Left
invert(root.Left)
invert(root.Right)
}
invert(root)
return root
}
// func invertTree(root *TreeNode) *TreeNode {
// if root == nil {
// return nil
// }
// right := invertTree(root.Right)
// left := invertTree(root.Left)
// root.Left = right
// root.Right = left
// return root
// }
func main() {
fmt.Println("vim-go")
}
|