Using the same JAVA code, I submit it first time ,got a TLE. But when I sumit it again, got a ACEEPT.


  • 0
    A

    It is my code:

    public class Solution {
    public void rotate(int[] nums, int k) {

        int len=nums.length;
        if(len==0)
            return ;
        
        k=k%len;
        if(k==0)
            return;
            
        reverse(nums,0,len-1);
        reverse(nums,0,k-1);
        reverse(nums,k,len-1);
        
    }
    
    private void reverse(int[] nums,int s,int e){
        
        while(s<e){
            
            int tmp=nums[s];
            nums[s]=nums[e];
            nums[e]=tmp;
            s++;
            e--;
        }
        
    }
    

    }


  • 0
    T

    Same here, so weird!


Log in to reply
 

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