Skip to content

Commit 15fb7ac

Browse files
committed
Add Merge two sorted lists Solution - s0ooo0k
1 parent 87d975c commit 15fb7ac

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

merge-two-sorted-lists/s0ooo0k.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
/*
3+
* 시간복잡도 O(m+n) m: list1의 길이, n: list2의 길이
4+
*/
5+
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
6+
if(list1==null) return list2;
7+
if(list2==null) return list1;
8+
9+
if(list1.val <= list2.val) {
10+
list1.next = mergeTwoLists(list1.next, list2);
11+
return list1;
12+
}
13+
else {/* */
14+
list2.next = mergeTwoLists(list1, list2.next);
15+
return list2;
16+
}
17+
}
18+
}
19+

0 commit comments

Comments
 (0)