My 8ms C solution


  • -1
    1
    void rotate(int* nums, int numsSize, int k) {
        int i;
        if(k > numsSize)
        k -= numsSize;
        int* temp = (int*)calloc(sizeof(int), numsSize);
        for(i = 0; i < k; i++)
           temp[i] = nums[numsSize - k + i];
        for(; i < numsSize; i++)
           temp[i] = nums[i - k];
    
         for(i = 0; i < numsSize; i++)
           nums[i] = temp[i];
     }

Log in to reply
 

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