invert-binary-tree

  • 递归
1
2
3
4
5
6
7
8
9
var invertTree = function(root) {
if (!root) {
return null;
}
[root.right, root.left] = [root.left, root.right];
invertTree(root.left);
invertTree(root.right);
return root;
};