Movatterモバイル変換


[0]ホーム

URL:


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

Commitc62555b

Browse files
committed
sort
1 parent5b410c9 commitc62555b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎list/MergeTwoLists_1206.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
packageAlgorithms.list;
2+
3+
importAlgorithms.algorithm.others.ListNode;
4+
5+
/**
6+
* Definition for singly-linked list.
7+
* public class ListNode {
8+
* int val;
9+
* ListNode next;
10+
* ListNode(int x) {
11+
* val = x;
12+
* next = null;
13+
* }
14+
* }
15+
*/
16+
publicclassMergeTwoLists_1206 {
17+
publicListNodemergeTwoLists(ListNodel1,ListNodel2) {
18+
ListNodedummy =newListNode(0);
19+
ListNodecur =dummy;
20+
21+
while (l1 !=null &&l2 !=null) {
22+
if (l1.val <l2.val) {
23+
cur.next =l1;
24+
l1 =l1.next;
25+
}else {
26+
cur.next =l2;
27+
l2 =l2.next;
28+
}
29+
cur =cur.next;
30+
}
31+
32+
if (l1 !=null) {
33+
cur.next =l1;
34+
}else {
35+
cur.next =l2;
36+
}
37+
38+
returndummy.next;
39+
}
40+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp