Easy enough to understand


  • 0
    2
    class Solution {
    public:
        void rotate(int nums[], int n, int k) {
    
            k %= n;
            
            int* tmp = new int[2*n+1];
            
            for(int i = 0; i < n; i++)
                tmp[i] = tmp[i+n] = nums[i];
            
            for(int i = 0; i < n; i++)
                nums[i] = tmp[i+n-k];
                
            delete tmp;
        }
    };

  • 0
    A

    This is not a O(1) solution.


Log in to reply
 

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