C++ vector<int> argument


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

Log in to reply
 

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