Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves may be changed.)
var swapPairs = function (head) { let ptr = head, start = true, pre = null; while (ptr && ptr.next) { let cur = ptr; let next = cur.next; cur.next = next.next; next.next = cur; if (start == true) { head = next; start = false; } else { pre.next = next; } pre = cur; ptr = cur.next;