leetcode链接:https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var reverseList = function(head) {
if (!head) return null
let prev = null
let current = head
let after = head.next
while (current) {
current.next = prev
prev = current
current = after
if (after) {
after = after.next
}
}
return prev
};