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 e08cf3a commit b6c9cdcCopy full SHA for b6c9cdc
reverse-linked-list/byol-han.js
@@ -0,0 +1,25 @@
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
+ * https://leetcode.com/problems/reverse-linked-list/
10
+ * @param {ListNode} head
11
+ * @return {ListNode}
12
13
+var reverseList = function (head) {
14
+ let prev = null;
15
+ let current = head;
16
+
17
+ while (current) {
18
+ const next = current.next; // 다음 노드 기억
19
+ current.next = prev; // 현재 노드가 이전 노드를 가리키도록 변경
20
+ prev = current; // prev를 현재 노드로 이동
21
+ current = next; // current를 다음 노드로 이동
22
+ }
23
24
+ return prev; // prev는 새로운 head
25
+};
0 commit comments