-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeList.java
More file actions
41 lines (37 loc) · 804 Bytes
/
Copy pathMergeList.java
File metadata and controls
41 lines (37 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* File Name:MergeList is created on 2020/8/14 9:38 下午 by lite
*
* Copyright (c) 2020, xiaoyujiaoyu technology All Rights Reserved.
*
*/
/**
* @author lite
* @Description:
* @date: 2020/8/14 9:38 下午
* @since JDK 1.8
*/
public class MergeList {
public ListNode mergeList(ListNode l1, ListNode l2) {
if (null == l1) {
return l2;
}
if (null == l2) {
return l1;
}
if (l1.val < l2.val) {
l1.next = mergeList(l1.next, l2);
return l1;
} else {
l2.next = mergeList(l1, l2.next);
return l2;
}
}
static class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
}