24. Swap Nodes in Pairs
202410101644
tags: #linked-list
var swapPairs = function(head) {
const dummy = new ListNode();
dummy.next = head;
let prev = dummy;
while (prev.next !== null && prev.next.next !== null) {
const first = prev.next;
const second = first.next;
const then = second.next;
first.next = then;
second.next = first;
prev.next = second;
prev = prev.next.next;
}
return dummy.next;
};