Below is my code


  • 0
    A

    void rotate(int nums[], int n, int k) {
    unsigned int i,j;
    int *temp;
    temp = malloc(sizeof(int)*k);
    for(i=0;i<k;i++){
    *temp = nums[n-1-i];
    temp++;
    }
    for(i=0;i<n-k;i++){
    nums[n-i-1] = nums[n-i-1-k];
    }
    for(i=0;i<k;i++){
    nums[i] = *(temp-1);
    temp--;
    }
    free(temp);
    }


Log in to reply
 

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