File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+ //! ์ถํ ๋ณต์ต ํ์ํ ๋ฌธ์
14+ const mergeTwoLists = function ( list1 , list2 ) {
15+ // ์ด ๋ถ๋ถ์ ์ ํ ์๊ฐ ๋ด์ ๋ ์ฌ๋ฆฌ์ง ๋ชปํด ai๋ก๋ถํฐ ํํธ๋ฅผ ๋ฐ์ ๋ก์ง์ ์์ฑ
16+ let temp = new ListNode ( 0 ) ;
17+ let cur = temp ;
18+
19+ while ( list1 !== null && list2 !== null ) {
20+ if ( list1 . val <= list2 . val ) {
21+ cur . next = list1 ;
22+ list1 = list1 . next ;
23+ } else {
24+ cur . next = list2 ;
25+ list2 = list2 . next ;
26+ }
27+ cur = cur . next ;
28+ }
29+
30+ cur . next = list1 !== null ? list1 : list2 ;
31+
32+ return temp . next ;
33+ } ;
You canโt perform that action at this time.
0 commit comments