170.Rotate List
1.Description(Medium)
2.Code
public ListNode rotateRight(ListNode head, int k) {
if(head==null){
return head;
}
ListNode current=head;
int len=1;
while(current.next!=null){
len++;
current=current.next;
}
current.next=head;
ListNode temp=current;
for(int i=0;i<len-k%len;i++){
temp=temp.next;
}
ListNode newhead=temp.next;
temp.next=null;
return newhead;
}Last updated