@@ -0,0 +1,1132 @@
+/***%0A * Given a list, rotate the list to the right by k places, where k is non-negative.%0A *%0A * For example:%0A * Given 1-%3E2-%3E3-%3E4-%3E5-%3ENULL and k = 2,%0A * return 4-%3E5-%3E1-%3E2-%3E3-%3ENULL.%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    // Solution 1: O(n), O(1)%0A    public ListNode rotateRight(ListNode head, int n) %7B%0A        if (head == null %7C%7C head.next == null)%0A            return head;%0A        ListNode n1 = head;%0A        ListNode n2 = head;%0A        while (n-- %3E 0) %7B %0A            if (n2.next == null) %7B%0A                n2 = head;%0A                continue;%0A            %7D%0A            n2 = n2.next;%0A        %7D%0A        if (n2 == head) return head;%0A        while (n2.next != null) %7B%0A            n1 = n1.next;%0A            n2 = n2.next;%0A        %7D%0A        ListNode ret = n1.next;%0A        n1.next = null;%0A        n2.next = head;%0A        return ret;%0A    %7D%0A    // Solution 2: find length through iteration, link end to head, then go k %25 length steps%0A    // O(n), O(1)%0A%7D%0A

add RotateList.java