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