public ListNode rotateRight(ListNode head, int n)
    {
        if (null == head || null == head.next)
            return head;

        ListNode p = head;
        int len = 0;

        while (p != null)
        {
            len++;
            p = p.next;
        }

        n %= len;

        if (n == 0)
            return head;

        ListNode r = null, end = head;
        int i = 0;
        p = head;
        while (p != null)
        {
            if (null == p.next)
                end = p;

            if (i < n)
            {
                p = p.next;
                ++i;
            }
            else if (i == n)
            {
                r = head;
                p = p.next;
                ++i;
            }
            else
            {
                r = r.next;
                p = p.next;
                ++i;
            }
        }

        ListNode h = r.next;
        end.next = head;
        r.next = null;

        return h;
    }