4 line cpp


  • 0
    S
    void rotate(vector<int>& nums, int k) {
        int n = nums.size();
        vector<int> numsCopy(nums);
        
        for(int i = 0; i < n; i++)
            nums[(i+k)%n] = numsCopy[i];
    }

Log in to reply
 

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