Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andreis
Last active June 21, 2017 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreis/9c02400c243af4a1fd71726480b784d9 to your computer and use it in GitHub Desktop.
Save andreis/9c02400c243af4a1fd71726480b784d9 to your computer and use it in GitHub Desktop.
// https://leetcode.com/problems/invert-binary-tree
/**
* 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 = invertTree(root.Right), invertTree(root.Left)
return root
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment