21 lines
314 B
Go
21 lines
314 B
Go
|
|
package main
|
||
|
|
|
||
|
|
type TreeNode struct {
|
||
|
|
Val int
|
||
|
|
Left *TreeNode
|
||
|
|
Right *TreeNode
|
||
|
|
}
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
|
||
|
|
}
|
||
|
|
func invertTree(root *TreeNode) *TreeNode {
|
||
|
|
if root == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
root.Left, root.Right = invertTree(root.Left), invertTree(root.Right)
|
||
|
|
root.Left, root.Right = root.Right, root.Left
|
||
|
|
return root
|
||
|
|
}
|