Status: Time Limit Exceeded


  • 0
    D

    I think I wrote the right code, but get error. Anyone could help explain this? Many thanks.

    public class Solution {

    public ListNode rotateRight(ListNode head, int n) {
        
        if(head == null || head.next == null) 
            return head;
            
        if(n == 0)
            return head;
            
        ListNode iter = head;
        int len = 1;
        int m = 1;
    
        while(iter.next != null) {
            len++;
        }
        
        iter.next = head;
        iter = iter.next;
        
        while(m < len - n) {
            iter = iter.next;
            m++;
        }
        
        ListNode returnNode = iter.next;
        iter.next = null;
        
        return returnNode;
    }
    

    }


Log in to reply
 

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