Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public ListNode rotateRight(ListNode head, int k) {
- if(head == null || k == 0 || head.next == null)
- return head;
- ListNode curr = head;
- int length = 1;
- while(curr.next != null) {
- length++;
- curr = curr.next;
- }
- curr.next = head;
- if(k % length!=0){
- for( int i = 0; i < length - (k%length); i++) {
- curr = curr.next;
- }}
- head = curr.next;
- curr.next = null;
- return head;
- }
- }
Add Comment
Please, Sign In to add comment