Skip to content

Instantly share code, notes, and snippets.

@FlandreDaisuki
Created June 13, 2015 16:18
Show Gist options
  • Save FlandreDaisuki/a48e6593e76e2ec6f2ee to your computer and use it in GitHub Desktop.
Save FlandreDaisuki/a48e6593e76e2ec6f2ee to your computer and use it in GitHub Desktop.
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {TreeNode}
*/
var invertTree = function(root) {
if (root.left !== null || root.right !== null) {
var rr, rl;
rl = invertTree(root.left);
rr = invertTree(root.right);
root.left = rr;
root.right = rl;
}
return root;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment