Skip to content

Commit fc126e9

Browse files
committedApr 21, 2019
LeetCode打卡第二十一天day21_InvertBinaryTree
1 parent febce15 commit fc126e9

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
 

‎InvertBinaryTree.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
Time:2019/4/21
3+
Title: Invert Binary Tree
4+
Difficulty: Easy
5+
Author: 小鹿
6+
---
7+
8+
9+
10+
## 题目:Invert Binary Tree(反转二叉树)
11+
12+
Invert a binary tree.
13+
14+
> 反转二叉树
15+
16+
**Example:**
17+
18+
Input:
19+
20+
```
21+
4
22+
/ \
23+
2 7
24+
/ \ / \
25+
1 3 6 9
26+
```
27+
28+
Output:
29+
30+
```
31+
4
32+
/ \
33+
7 2
34+
/ \ / \
35+
9 6 3 1
36+
```
37+
38+
39+
40+
## Solve:
41+
42+
###### ▉ 问题分析
43+
44+
45+
46+
47+
48+
###### ▉ 算法思路
49+
50+
51+
52+
53+
54+
###### ▉ 代码实现
55+
56+
```javascript
57+
var invertTree = function(root) {
58+
//判断当前树是否为 null
59+
if(root == null) return root;
60+
61+
let right = root.right;
62+
let left = root.left;
63+
root.right = left;
64+
root.left = right;
65+
66+
invertTree(left);
67+
invertTree(right);
68+
return root;
69+
};
70+
```
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+

0 commit comments

Comments
 (0)
Failed to load comments.