题目链接
https://leetcode.com/problems/invert-binary-tree/
题目原文
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
Trivia:
This problem was inspired by this original tweet by Max Howell:Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
题目翻译
翻转二叉树。
花絮:
Max Howell 在 tweet 中说:
谷歌:虽然我们的工程师中有90%的人在用你写的软件,但你居然不能再白板上写个翻转二叉树的代码,滚吧。
思路方法
思路一
(DFS)递归算法,每次递归交换当前节点的左右子树,同时对左右子树做同样的处理。
代码一