206. 反转链表
1:17:41
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var reverseList = function(head) {
if(!head)return null;
let pre=null,cur=head;
while(cur){
[cur.next,pre,cur]=[pre,cur,cur.next]
// let next=cur.next;
// cur.next=pre;
// pre=cur;
// cur=next;
}
return pre;
};
1

浙公网安备 33010602011771号