Skip to content

Commit 6990e09

Browse files
committed
Time: 87 ms (15.97%), Space: 43.8 MB (63.94%) - LeetHub
1 parent 3299fd3 commit 6990e09

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 [prev, current] = [null, head]
14+
while(current) {
15+
[current.next, prev, current] = [prev, current, current.next]
16+
}
17+
return prev
18+
};

0 commit comments

Comments
 (0)