Java Solution || One pointer solution || O(n) complexity


#1

public ListNode rotateRight(ListNode A, int B) {
if(A == null || B == 0) return A;

    ListNode node = A;
    int count = 1;
    
    while(node.next != null) {
        node = node.next;
        count++;
    }
    
    B = B % count;
    B = count - B;
    
    if(B == 0) return A;
    
    node.next = A;
    node = node.next;
   
    while(B-- > 1) node= node.next;

    A = node.next;
    node.next = null;
    return A;
}