Re:Invert a binary tree on LeetCode
by alexchamberlain on Saturday June 13, 2015 @06:48AM
(#9710594)
Very interesting that the 3 answers here are 2 Python and 1 C++; I feared the world had descended into a JS downward spiral, but clearly not.
[ Parent
| on HN ]
I am your fear:
var invertTree = function(root) {
if (!root) {
return root;
}
var left = root.left;
var right = root.right;
root.right = invertTree(left);
root.left = invertTree(right);
return root;
};
Re:Invert a binary tree on LeetCode
by andresmanz on Saturday June 13, 2015 @08:47AM
(#9710837)
That was my fear, too. And I also will go with C++ first.