4 lines concise and easy understand c++ solution space O(N), only one pass


  • 0
    A
    class Solution {
    public:
        void rotate(vector<int>& nums, int k) {
            int n = nums.size();
            vector<int> res(nums.begin() + n - k % n, nums.end());
            for(int i = 0; i < n - k % n; i++) res.push_back(nums[i]);
            swap(res, nums);
        }
    };

  • 0
    C
    This post is deleted!

Log in to reply
 

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