Skip to content

Commit 24bf0ae

Browse files
author
공예영
committed
Time: 0 ms (100%), Space: 58.2 MB (19.4%) - LeetHub
1 parent 0ed26cd commit 24bf0ae

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 {ListNode}
11+
*/
12+
var reverseList = function(head) {
13+
let current = head;
14+
let prev = null;
15+
16+
while(current){
17+
const next = current.next;
18+
current.next = prev;
19+
prev = current;
20+
current = next;
21+
}
22+
return prev;
23+
};

0 commit comments

Comments
 (0)