FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_100/LeetCode_21_100.java at master · algorithm001/algorithm · GitHub
algorithm001
/
algorithm
Public
Notifications
You must be signed in to change notification settings
Fork
148
Star
118
Code
Issues
548
Pull requests
46
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_01
/
id_100
/
LeetCode_21_100.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (28 loc) · 808 Bytes
Breadcrumbs
algorithm
/
Week_01
/
id_100
/
LeetCode_21_100.java
Copy path
File metadata and controls
29 lines (28 loc) · 808 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class
Solution
{
public
ListNode
mergeTwoLists
(
ListNode
n1
,
ListNode
n2
) {
ListNode
result
=
new
ListNode
(
0
);
ListNode
n0
=
result
;
while
(
n1
!=
null
&&
n1
!=
null
) {
//System.out.println("n1-----" + n1.val + "--------n2-------" + n2.val
if
(
n1
.
val
<
n2
.
val
) {
n0
.
next
=
new
ListNode
(
n1
.
val
);
n1
=
n1
.
next
;
}
else
{
n0
.
next
=
new
ListNode
(
n2
.
val
);
n2
=
n2
.
next
;
}
n0
=
n0
.
next
;
}
if
(
n1
!=
null
)
n0
.
next
=
n1
;
else
n0
.
next
=
n2
;
return
result
.
next
;
}
}
Back
|
FazBrowse Home
|
New Git URL