my c solution which is easy to understand


  • 0
    H
    void rotate(int* nums, int numsSize, int k) {
        int *s=malloc(sizeof(int)*numsSize);
        int j=0;
        while(k>numsSize)
        {
            k-=numsSize;
        }
        for(int i=numsSize-k;i<numsSize;i++)
        {
            s[j++]=nums[i];
        }
        for(int i=0;i<numsSize-k;i++)
        {
            s[j++]=nums[i];
        }
        for(int i=0;i<numsSize;i++)
        {
            nums[i]=s[i];
        }
    }
    

Log in to reply
 

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