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 67ab0cd commit 3c172daCopy full SHA for 3c172da
โreverse-linked-list/wogha95.js
@@ -0,0 +1,28 @@
1
+/**
2
+ * TC: O(N)
3
+ * SC: O(1)
4
+ */
5
+
6
7
+ * Definition for singly-linked list.
8
+ * function ListNode(val, next) {
9
+ * this.val = (val===undefined ? 0 : val)
10
+ * this.next = (next===undefined ? null : next)
11
+ * }
12
13
14
+ * @param {ListNode} head
15
+ * @return {ListNode}
16
17
+var reverseList = function (head) {
18
+ let pointer = null;
19
20
+ while (head) {
21
+ // 1. ์ ๋ต ๋ฆฌ์คํธ์ ๋งจ ์์ ์๋ก์ด ๋ ธ๋๋ฅผ ์ถ๊ฐ
22
+ pointer = new ListNode(head.val, pointer);
23
+ // 2. head๋ ๋ค์ ๋ ธ๋๋ก ์ด๋
24
+ head = head.next;
25
+ }
26
27
+ return pointer;
28
+};
0 commit comments