1

I was going through leetcode solution for a question

Where I stumbled upon this algo

var insertionSortList = function(head) {
    let newHead = new ListNode(0)
    while(head){
        const t = head
        head = head.next
        let cur = newHead
        while(cur){
            if(!cur.next || t.val <= cur.next.val){
                [cur.next, t.next] = [t, cur.next]
                break
            }
            cur = cur.next
        }
    }
    return newHead.next
};

Can someone please explain me what is [cur.next, t.next] = [t, cur.next] here?

Diza Moa
  • 83
  • 4

0 Answers0