Skip to content

Latest commit

 

History

History
23 lines (20 loc) · 374 Bytes

226_invert_binary_tree.md

File metadata and controls

23 lines (20 loc) · 374 Bytes
/**
 * 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  := invertTree(root.Left)
    right := invertTree(root.Right)
    root.Left = right
    root.Right = left
    return root
}