Skip to main content

226. Invert Binary Tree

分析

这个操作能发生在先 和 后  中不可

题解

function invertTree(root: TreeNode | null): TreeNode | null {
if (!root) {
return root
}

invertTree(root.left)
invertTree(root.right)

const temp = root.left
root.left = root.right
root.right = temp

return root
};
function invertTree(root: TreeNode | null): TreeNode | null {
if (!root) {
return root
}

const temp = root.left
root.left = root.right
root.right = temp

invertTree(root.left)
invertTree(root.right)

return root
};