File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
+ * 2차
3
+ * Tony님 풀이 참고해서 SC 개선
4
+ *
2
5
* TC: O(N)
3
6
* SC: O(1)
7
+ * 순회동안 노드 생성하지 않으므로 공간복잡도가 상수다.
8
+ *
9
+ * N: linked-list length
10
+ */
11
+
12
+ /**
13
+ * Definition for singly-linked list.
14
+ * function ListNode(val, next) {
15
+ * this.val = (val===undefined ? 0 : val)
16
+ * this.next = (next===undefined ? null : next)
17
+ * }
18
+ */
19
+ /**
20
+ * @param {ListNode } head
21
+ * @return {ListNode }
22
+ */
23
+ var reverseList = function ( head ) {
24
+ let pointer = null ;
25
+
26
+ while ( head !== null ) {
27
+ let temp = head . next ;
28
+ head . next = pointer ;
29
+ pointer = head ;
30
+ head = temp ;
31
+ }
32
+
33
+ return pointer ;
34
+ } ;
35
+
36
+ /**
37
+ * 1차
38
+ * TC: O(N)
39
+ * linked-list 길이 만큼 순회
40
+ *
41
+ * SC: O(N)
42
+ * linked-list 길이만큼 생성
43
+ *
44
+ * N: linked-list length
4
45
*/
5
46
6
47
/**
You can’t perform that action at this time.
0 commit comments