We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d818f00 commit bd7cc59Copy full SHA for bd7cc59
โmerge-two-sorted-lists/forest000014.java
@@ -0,0 +1,37 @@
1
+/**
2
+
3
+ (n = list1.length + list2.length)
4
+ ์๊ฐ ๋ณต์ก๋: O(n)
5
+ - ์ต์ ์ ๊ฒฝ์ฐ ์ ์ฒด ๋ ธ๋ ์ํ
6
+ ๊ณต๊ฐ ๋ณต์ก๋: O(n)
7
+ - ์ต์ ์ ๊ฒฝ์ฐ ์ ์ฒด ๋ ธ๋๋งํผ ์ ๋ ธ๋ ์์ฑ
8
9
+ */
10
+class Solution {
11
+ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
12
+ ListNode head = new ListNode();
13
+ ListNode curr = head;
14
15
+ while (true) {
16
+ if (list1 == null) {
17
+ curr.next = list2;
18
+ break;
19
+ } else if (list2 == null) {
20
+ curr.next = list1;
21
22
+ }
23
24
+ if (list1.val <= list2.val) {
25
+ curr.next = new ListNode(list1.val);
26
+ curr = curr.next;
27
+ list1 = list1.next;
28
+ } else {
29
+ curr.next = new ListNode(list2.val);
30
31
+ list2 = list2.next;
32
33
34
35
+ return head.next;
36
37
+}
0 commit comments