Created
June 13, 2015 16:18
-
-
Save FlandreDaisuki/a48e6593e76e2ec6f2ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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