1 public ListNode swapPairs(ListNode head) { 2 if (head == null || head.next == null) return head; 3 ListNode a = head, b = head.next, c, last = null; 4 head = b; 5 while (a != null && b != null) { 6 c = b.next; 7 b.next = a; 8 a.next = c; 9 if (last != null) last.next = b; 10 last = a; 11 12 a =c; 13 if (a != null) b = a.next; 14 } 15 return head; 16 }