@@ -0,0 +1,979 @@
+package leetcode.swap_nodes_in_pairs;%0A%0Aimport java.util.ArrayList;%0A%0Aimport common.ListNode;%0A%0Apublic class Solution %7B%0A%09public ListNode swapPairs(ListNode head) %7B%0A%09%09if(head == null %7C%7C head.next == null) return head;%0A%09%09ListNode ret = head.next;%0A%09%09ListNode cur = head;%0A%09%09ListNode prev = null;%0A%09%09while(cur != null && cur.next != null)%7B%0A%09%09%09ListNode nxt = cur.next;%0A%09%09%09cur.next = nxt.next;%0A%09%09%09nxt.next = cur;%0A%09%09%09if(prev != null)%7B%0A%09%09%09%09prev.next = nxt;%0A%09%09%09%7D%0A%09%09%09prev = cur;%0A%09%09%09cur = cur.next;%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%0A%09public static void dump(ListNode head)%7B%0A%09%09ListNode cur = head;%0A%09%09while(cur != null)%7B%0A%09%09%09System.err.print(cur.val + %22, %22);%0A%09%09%09cur = cur.next;%0A%09%09%7D%0A%09%09System.err.println(%22%22);%0A%09%7D%0A%09%0A%09public static void main(String%5B%5D args)%7B%0A%09%09final int N = 3;%0A%09%09ArrayList%3CListNode%3E ary = new ArrayList%3CListNode%3E();%0A%09%09for(int i = 0; i %3C N; i++)%7B%0A%09%09%09ary.add(new ListNode(i));%0A%09%09%09if(i %3E 0) ary.get(i - 1).next = ary.get(i);%0A%09%09%7D%0A%09%09ListNode ret = new Solution().swapPairs(ary.get(0));%0A%09%09dump(ret);%0A%09%7D%0A%7D

Add java solution for 24. Swap Nodes in Pairs