JAVA 7 solution


#1
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     public int val;
 *     public ListNode next;
 *     ListNode(int x) { val = x; next = null; }
 * }
 */
public class Solution {
    public ListNode rotateRight(ListNode A, int B) {
        if(A.next == null){
            return A;
        }
        ListNode head = A;
        int l = 0; 
        ListNode b = null;
        while(A!=null){
            b = A;
            l++;
            A = A.next;
        }
        A = head;
        if(B%l == 0){
            return A;
        }
        for(int i = 0 ; i < l-B%l-1 ; i++){
            A = A.next;
        }
        ListNode a = A.next;
        A.next = null;
        b.next = head;
        return a;
    }
}