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.
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;
};