We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f819319 commit fc5e333Copy full SHA for fc5e333
reverse-linked-list/hwanmini.js
@@ -0,0 +1,28 @@
1
+// 시간복잡도: O(n)
2
+// 공간복잡도: O(1)
3
+
4
+/**
5
+ * Definition for singly-linked list.
6
+ * function ListNode(val, next) {
7
+ * this.val = (val===undefined ? 0 : val)
8
+ * this.next = (next===undefined ? null : next)
9
+ * }
10
+ */
11
12
+ * @param {ListNode} head
13
+ * @return {ListNode}
14
15
+var reverseList = function(head) {
16
+ let curNode = head
17
+ let preNode = null
18
19
+ while (curNode) {
20
+ const nextNode = curNode.next
21
+ curNode.next = preNode
22
+ preNode = curNode
23
+ curNode = nextNode
24
+ }
25
26
27
+ return preNode
28
+};
0 commit comments