public ListNode rotateRight(ListNode head, int k) {
        if (head == null || head.next == null)
            return head;
        ListNode temp = head;
        int count = 0;
        while (temp != null) {
            temp = temp.next;
            ++count;
        }
        k = k % count;
        if (k == 0)
            return head;
        ListNode fast = head;
        while (k > 0) {
            fast = fast.next;
            --k;
        }
        ListNode slow = head;
        while (fast.next != null) {
            slow = slow.next;
            fast = fast.next;
        }
        temp = slow.next;
        fast.next = head;
        slow.next = null;
        return temp;
    }