61. Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative.
For example:Given1->2->3->4->5->NULL
and k =2
,return4->5->1->2->3->NULL.

public class Solution {
    public ListNode rotateRight(ListNode head, int k) {
        if(head==null||k==0)
            return head;
        ListNode p = head;
        int len = 1;
        while(p.next!=null)
        {
            p = p.next;
            len++;
        }
        p.next = head;
        k = k%len;
        for(int i=0;i

你可能感兴趣的:(61. Rotate List)