思路
传说中的反转二叉树,递归交换
code
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func invertTree(root *TreeNode) *TreeNode {
if root == nil {
return root
}
root.Left = invertTree(root.Left)
root.Right = invertTree(root.Right)
root.Left, root.Right = root.Right, root.Left
return root
}
更多内容请移步我的repo: https://github.com/anakin/golang-leetcode