26 lines
409 B
Go
26 lines
409 B
Go
package main
|
|
|
|
type TreeNode struct {
|
|
Val int
|
|
Left *TreeNode
|
|
Right *TreeNode
|
|
}
|
|
|
|
/**
|
|
* Definition for a binary tree node.
|
|
* type TreeNode struct {
|
|
* Val int
|
|
* Left *TreeNode
|
|
* Right *TreeNode
|
|
* }
|
|
*/
|
|
func invertTree(root *TreeNode) *TreeNode {
|
|
if root == nil {
|
|
return nil
|
|
}
|
|
root.Left, root.Right = root.Right, root.Left
|
|
invertTree(root.Left)
|
|
invertTree(root.Right)
|
|
return root
|
|
}
|