@@ -0,0 +1,1050 @@
+/***%0A * Given a linked list, swap every two adjacent nodes and return its head.%0A *%0A * For example,%0A * Given 1-%3E2-%3E3-%3E4, you should return the list as 2-%3E1-%3E4-%3E3.%0A *%0A * Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.%0A */%0A/**%0A * Definition for singly-linked list.%0A * public class ListNode %7B%0A *     int val;%0A *     ListNode next;%0A *     ListNode(int x) %7B%0A *         val = x;%0A *         next = null;%0A *     %7D%0A * %7D%0A*/%0Apublic class Solution %7B%0A    public ListNode swapPairs(ListNode head) %7B%0A        if (head == null %7C%7C head.next == null) return head;%0A        ListNode ret = new ListNode(0);%0A        ListNode prev, cur, next;%0A        ret.next = head;%0A%0A        for (prev = ret, cur = head, next = head.next; %0A                next != null;%0A                prev = cur, cur = cur.next, %0A                next = cur == null? null : cur.next) %7B%0A            prev.next = next;%0A            cur.next = next.next;%0A            next.next = cur;%0A                %7D%0A        return ret.next;%0A    %7D%0A%7D%0A

add SwapNodesinPairs.java