File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for singly-linked list.
3
+ * public class ListNode {
4
+ * int val;
5
+ * ListNode next;
6
+ * ListNode() {}
7
+ * ListNode(int val) { this.val = val; }
8
+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9
+ * }
10
+ */
11
+ /**
12
+ ์ ๋ ฌ๋ ๋งํฌ๋ ๋ฆฌ์คํธ list1๊ณผ list2๊ฐ ์ฃผ์ด์ง ๋ ๋ ๋ฆฌ์คํธ๋ฅผ ํ๋์ ์ ๋ ฌ๋ ๋ฆฌ์คํธ๋ก ๋ฐํํ๋๋ก ๊ตฌํํ์ธ์.
13
+ */
14
+ class Solution {
15
+
16
+ // ์๊ฐ ๋ณต์ก๋: O(l1 + l2), l1๊ณผ l2๋ ๋ฆฌ์คํธ ๊ฐ๊ฐ์ ๊ธธ์ด
17
+ public ListNode mergeTwoLists (ListNode list1 , ListNode list2 ) {
18
+ if (list1 == null || list2 == null ) {
19
+ return list1 == null ? list2 : list1 ;
20
+ }
21
+ if (list1 .val < list2 .val ) {
22
+ list1 .next = mergeTwoLists (list1 .next , list2 );
23
+ return list1 ;
24
+ } else {
25
+ list2 .next = mergeTwoLists (list2 .next , list1 );
26
+ return list2 ;
27
+ }
28
+ }
29
+ }
30
+
You canโt perform that action at this time.
0 commit comments