Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1fbb428

Browse files
add q226
1 parent e7dd9f3 commit 1fbb428

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

‎.idea/workspace.xml‎

Lines changed: 20 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
* [q21_合并两个有序链表](/src/递归/q21_合并两个有序链表)
6969
* [q101_对称二叉树](/src/递归/q101_对称二叉树)
70+
* [q226_翻转二叉树](/src/递归/q226_翻转二叉树)
7071
* [q236_二叉树的最近公共祖先](/src/递归/q236_二叉树的最近公共祖先)
7172

7273
### 分治法/二分法
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package 递归.q226_翻转二叉树;
2+
3+
/**
4+
* 递归 o(n)
5+
*/
6+
public class Solution {
7+
8+
public TreeNode invertTree(TreeNode root) {
9+
if (root == null) {
10+
return null;
11+
}
12+
TreeNode temp = root.left;
13+
root.left = root.right;
14+
root.right = temp;
15+
if (root.left != null) {
16+
invertTree(root.left);
17+
}
18+
if (root.right != null) {
19+
invertTree(root.right);
20+
}
21+
return root;
22+
}
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package 递归.q226_翻转二叉树;
2+
3+
public class TreeNode {
4+
int val;
5+
TreeNode left;
6+
TreeNode right;
7+
8+
TreeNode(int x) {
9+
val = x;
10+
}
11+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /