fork download
  1. #include <iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5. // create a program to rotate an elements in an array
  6. class Solution {
  7. public:
  8. void rotate(vector<int>& nums, int k) {
  9. int n=nums.size();
  10. k=k%n;
  11. // create a vector to store the elements in an array
  12. vector<int> v1;
  13. // Run the loop for the given problems
  14. for(int i=0;i<n;i++){
  15. if(i<k){
  16. v1.push_back(nums[n+i-k]);
  17.  
  18. }
  19. else{
  20. v1.push_back(nums[i-k]);
  21. }
  22.  
  23.  
  24. }
  25. for(int i = 0; i < v1.size(); ++i){
  26. nums[i] = v1[i];
  27. }
  28.  
  29. }
  30. };
  31.  
  32. int main() {
  33. // your code goes here
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty