- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution21.java
More file actions
Latest commit
executable file
·39 lines (33 loc) · 717 Bytes
/
Copy pathSolution21.java
File metadata and controls
executable file
·39 lines (33 loc) · 717 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
/**
* Created by slade on 2019/6/4.
*/
publicclassSolution21 {
publicListNodemergeTwoLists(ListNodel1, ListNodel2) {
ListNodeln1 = newListNode(0);
ListNodeln2 = ln1;
while (l1 !=null && l2!=null){
if (l1.val<=l2.val){
ln2.next = l1;
l1 = l1.next;
}else {
ln2.next = l2;
l2 = l2.next;
}
ln2 = ln2.next;
}
if (l1==null){
ln2.next=l2;
}
if (l2==null){
ln2.next=l1;
}
returnln1.next;
}
}
classListNode {
intval;
ListNodenext;
ListNode(intx) {
val = x;
}
}