11[#0226-invert-binary-tree]
2- = 226. Invert Binary Tree
2+ = 226. 翻转二叉树
33
4- { leetcode} /problems/invert-binary-tree/[LeetCode - Invert Binary Tree ^]
4+ https:// leetcode.cn /problems/invert-binary-tree/[LeetCode - 226. 翻转二叉树 ^]
55
6- Invert a binary tree.
6+ 给你一棵二叉树的根节点 `root` ,翻转这棵二叉树,并返回其根节点。
77
8- .Example:
9- ----
10- Input:
11-
12- 4
13- / \
14- 2 7
15- / \ / \
16- 1 3 6 9
17-
18- Output:
19- 4
20- / \
21- 7 2
22- / \ / \
23- 9 6 3 1
24- ----
8+ *示例 1:*
9+
10+ image::images/0226-01.jpg[{image_attr}]
11+
12+ ....
13+ 输入:root = [4,2,7,1,3,6,9]
14+ 输出:[4,7,2,9,6,3,1]
15+ ....
16+
17+ *示例 2:*
2518
26- *Trivia:*
19+ image::images/0226-02.jpg[{image_attr}]
2720
28- This problem was inspired by https://twitter.com/mxcl/status/608682016205344768[this original tweet] by https://twitter.com/mxcl[Max Howell (@mxcl)^]:
21+ ....
22+ 输入:root = [2,1,3]
23+ 输出:[2,3,1]
24+ ....
2925
30- ****
31- 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.
32- ****
26+ *示例 3:*
27+
28+ ....
29+ 输入:root = []
30+ 输出:[]
31+ ....
32+
33+ *提示:*
34+
35+ * 树中节点数目范围在 `[0, 100]` 内
36+ * `+-100 <= Node.val <= 100+`
3337
3438
3539== 思路分析
3640
3741D瓜哥也不会做这道题,现在可以说跟大神一个水平了,😆
3842
43+ image::images/0226-10.png[{image_attr}]
44+
45+ TIP: 现在D瓜哥可以顺利做出这道题,水平稳超大神,😁😁
46+
3947其实,思路很简单:就是递归地反转每棵树即可。
4048
41- image::images/0226-01.png[{image_attr}]
49+ image::images/0226-11.png[{image_attr}]
50+
51+ 动图演示如下:
52+
53+ image::images/0226-12.gif[{image_attr}]
4254
4355[[src-0226]]
4456[tabs]
@@ -60,9 +72,22 @@ include::{sourcedir}/_0226_InvertBinaryTree.java[tag=answer]
6072include::{sourcedir}/_0226_InvertBinaryTree_2.java[tag=answer]
6173----
6274--
75+
76+ 三刷::
77+ +
78+ --
79+ [{java_src_attr}]
80+ ----
81+ include::{sourcedir}/_0226_InvertBinaryTree_3.java[tag=answer]
82+ ----
83+ --
6384====
6485
86+
6587== 参考资料
6688
67- . https://leetcode.cn/problems/invert-binary-tree/solutions/415160/fan-zhuan-er-cha-shu-by-leetcode-solution/?envType=study-plan-v2&envId=selected-coding-interview[226. 翻转二叉树 - 官方题解^]
68- . https://leetcode.cn/problems/invert-binary-tree/solutions/2361621/226-fan-zhuan-er-cha-shu-fen-zhi-qing-xi-tqlf/?envType=study-plan-v2&envId=selected-coding-interview[226. 翻转二叉树 - 深度优先搜索,清晰图解^]
89+ . https://leetcode.cn/problems/invert-binary-tree/solutions/2713610/shi-pin-shen-ru-li-jie-di-gui-pythonjava-zhqh/[226. 翻转二叉树 - 两种递归写法^]
90+ . https://leetcode.cn/problems/invert-binary-tree/solutions/73159/dong-hua-yan-shi-liang-chong-shi-xian-226-fan-zhua/[226. 翻转二叉树 - 动画演示 两种实现^]
91+ . https://leetcode.cn/problems/invert-binary-tree/solutions/415507/shou-hua-tu-jie-san-chong-xie-fa-di-gui-liang-chon/[226. 翻转二叉树 - 「手画图解」剖析Howell大神没写出的面试题^]
92+ . https://leetcode.cn/problems/invert-binary-tree/solutions/415160/fan-zhuan-er-cha-shu-by-leetcode-solution/[226. 翻转二叉树 - 官方题解^]
93+ . https://leetcode.cn/problems/invert-binary-tree/solutions/2361621/226-fan-zhuan-er-cha-shu-fen-zhi-qing-xi-tqlf/[226. 翻转二叉树 - 深度优先搜索,清晰图解^]
0 commit comments