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 e0d5122

Browse files
committed
提交226
1 parent 3aecd08 commit e0d5122

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

‎leetcode/src/main/java/com/mistray/link/MergeTwoSortedLists21.java‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,20 @@ public static void main(String[] args) {
1515
}
1616

1717
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
18-
// 当l1为空,返回l2
1918
if (l1 == null) {
2019
return l2;
2120
}
22-
23-
// 当l2位空,返回l1
2421
if (l2 == null) {
2522
return l1;
2623
}
2724

28-
// 当l1的值小于l2时
29-
if (l1.val < l2.val) {
30-
l1.next = mergeTwoLists(l1.next, l2);
31-
return l1;
32-
} else {
25+
if (l1.val > l2.val) {
3326
l2.next = mergeTwoLists(l2.next, l1);
3427
return l2;
28+
} else {
29+
l1.next = mergeTwoLists(l2, l1.next);
30+
return l1;
3531
}
36-
3732
}
3833

3934

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.mistray.tree;
2+
3+
/**
4+
* @author ZJY(MistRay)
5+
* @Project algorithm-study
6+
* @Package com.mistray.tree
7+
* @create 2020年03月05日 16:57
8+
* @Desc
9+
*/
10+
public class InvertBinaryTree226 {
11+
public static void main(String[] args) {
12+
TreeNode root = new TreeNode(4);
13+
root.left = new TreeNode(2);
14+
root.left.left = new TreeNode(1);
15+
root.left.right = new TreeNode(3);
16+
root.right = new TreeNode(7);
17+
root.right.right = new TreeNode(9);
18+
root.right.left = new TreeNode(6);
19+
invertTree(root);
20+
}
21+
22+
public static TreeNode invertTree(TreeNode root) {
23+
if (root == null) {
24+
return null;
25+
}
26+
TreeNode left = invertTree(root.left);
27+
TreeNode right = invertTree(root.right);
28+
root.right = left;
29+
root.left = right;
30+
return root;
31+
}
32+
}

‎leetcode/src/main/java/com/mistray/tree/MergeTwoBinaryTrees617.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public static void main(String[] args) {
1616
public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
1717
if (t1 == null && t2 == null) {
1818
return null;
19-
} else if (t1 == null) {
19+
}
20+
if (t1 == null) {
2021
return t2;
2122
} else if (t2 == null) {
2223
return t1;

0 commit comments

Comments
(0)

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