rotate string / array

https://leetcode.com/problems/rotate-array/

code

class Solution {
public:
    void rotate(vector<int>& nums, int k) {
        if(nums.size() == 0)
        {
            return ;
        }
        vector<int> shadow;
        int realk = k%nums.size();

        for(int i = 0; i<nums.size(); i++)
        {
            int index = (i+nums.size()-realk)%nums.size();
            shadow.push_back(nums[index]);
        }

        nums = shadow;
    }
};

results matching ""

    No results matching ""