luoheng
10/6/2019 - 8:19 AM

invertTree

/**
 * 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
    }
    left, right := root.Left, root.Right
    root.Left = invertTree(right)
    root.Right = invertTree(left)
    return root
}