My java solution


  • 0
    C
    public class Solution {
        public ListNode rotateRight(ListNode head, int k) {
            ListNode n = head;
            int length = 1;
            if (head == null || k == 0) return head;
            while (n.next != null) {
                n = n.next;
                length += 1;
            }
            n.next = head;
            for (int i = 0; i < length-k%length ; i++)
                n = n.next;
            head = n.next;
            n.next = null;
            return head;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.