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