File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-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 } head
10+ * @return {void } Do not return anything, modify head in-place instead.
11+ */
12+ var reorderList = function ( head ) {
13+ const nodes = { } ;
14+ let currentNode = head ;
15+ let i = 0 ;
16+ while ( currentNode ) {
17+ nodes [ i ] = currentNode ;
18+ currentNode = currentNode . next ;
19+ i ++ ;
20+ }
21+
22+ i -- ;
23+
24+ for ( let j = 0 ; j < ( i / 2 ) ; j ++ ) {
25+ nodes [ j ] . next = nodes [ i - j ] ;
26+ nodes [ i - j ] . next = nodes [ j + 1 ] ;
27+ console . log ( j )
28+ }
29+
30+ nodes [ Math . ceil ( i / 2 ) ] . next = null ;
31+ } ;
32+
33+ // 시간 복잡도: O(n)
34+ // 공간 복잡도: O(n)
You can’t perform that action at this time.
0 commit comments