@@ -0,0 +1,844 @@
+package com.yan.leetcode;%0A%0Apublic class SwapNodesInPairs %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09ListNode head = new ListNode(1);%0A%09%09head.next = new ListNode(2);%0A%09%09head.next.next = new ListNode(3);%0A%09%09head.next.next.next = new ListNode(4);%0A%09%09head.next.next.next.next = new ListNode(5);%0A%0A%09%09head = swapPairs(head);%0A%0A%09%09System.out.println(head);%0A%0A%09%7D%0A%0A%09private static ListNode swapPairs(ListNode head) %7B%0A%09%09if (head == null %7C%7C head.next == null) %7B%0A%09%09%09return head;%0A%09%09%7D%0A%09%09// %E8%B4%9F%E8%B4%A3%E7%BB%93%E6%9E%9C%0A%09%09ListNode result = new ListNode(0);%0A%09%09// %E8%B4%9F%E8%B4%A3%E7%BB%93%E6%9E%9C%E7%9A%84%E6%8C%87%E9%92%88%0A%09%09ListNode p = result;%0A%09%09// head%E8%B4%9F%E8%B4%A3%E5%8E%9F%E6%9D%A5%E9%93%BE%E8%A1%A8%E7%9A%84%E6%8C%87%E9%92%88%0A%09%09while (head != null) %7B%0A%09%09%09ListNode nextNode = head.next;%0A%09%09%09if (nextNode == null) %7B%0A%09%09%09%09p.next = head;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%0A%09%09%09p.next = nextNode;%0A%09%09%09head.next = nextNode.next;%0A%09%09%09nextNode.next = head;%0A%0A%09%09%09head = head.next;%0A%09%09%09p = p.next.next;%0A%0A%09%09%7D%0A%0A%09%09return result.next;%0A%09%7D%0A%0A%7D%0A

swap nodes in pairs