C++ solution ,o(n)space,o(n)time


  • 2
    H

    use memcpy
    class Solution {
    public:
    void rotate(int nums[], int n, int k) {
    int * temp = new int [n];
    if(k>n)
    k = k%n;
    memcpy(temp,nums+n-k,k*sizeof(int));
    memcpy(temp+k,nums,(n-k)sizeof(int));
    memcpy(nums,temp,n
    sizeof(int));
    }
    };


Log in to reply
 

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