如果根节点不为空,左右节点交换,很简单:
function invertTree(root) {
if (root !== null) {
var temp = root.left;
root.left = root.right;
root.right = temp;
invertTree(root.left);
invertTree(root.right);
}
return root
};
如果根节点不为空,左右节点交换,很简单:
function invertTree(root) {
if (root !== null) {
var temp = root.left;
root.left = root.right;
root.right = temp;
invertTree(root.left);
invertTree(root.right);
}
return root
};