Shu-How Zの小窝

Loading...

206. 反转链表

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

posted @ 2026-04-03 18:27  KooTeam  阅读(1)  评论(0)    收藏  举报