My c++ solution


  • 0
    Z
    void rotate(vector<int>& nums, int k) {
      vector<int>res;
      int len = nums.size();
      k = k%len;
      for (int i = 0; i < len; i++)
      {
    	nums.push_back(nums[i]);
      }
      for (int i = len - k; i < 2*len-k; i++)
      {
    	res.push_back(nums[i]);
      }
    
      nums = res;
    }

Log in to reply
 

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