一、题目
Invert a binary tree.
  Example:
  Input:
4
/ \
2 7
/ \ / \
1 3 6 9
  Output:
4
/ \
7 2
/ \ / \
9 6 3 1
二、题目大意
交换二叉树的左右节点
三、解题思路
递归交换左右节点
四、代码实现
const invertTree = (root) => {
if (!root) {
return root
}
const temp = root.left
root.left = root.right
root.right = temp
invertTree(root.left)
invertTree(root.right)
return root
}
如果本文对您有帮助,欢迎关注微信公众号,为您推送更多大前端相关的内容, 欢迎留言讨论,ε=ε=ε=┏(゜ロ゜;)┛。
![](https://user-images.githubusercontent.com/17818249/42768887-3afba45e-8953-11e8-920b-b5ce001adf81.jpg)
您还可以在这些地方找到我: