226. 翻转二叉树

翻转一棵二叉树

链接

1
2
3
4
5
6
7
8
9
function invertTree(root: TreeNode | null): TreeNode | null {
if (root === null) return root
const temp = root.left
root.left = root.right
root.right = temp
invertTree(root.left)
invertTree(root.right)
return root
}