3 lines C++ code


  • 0
    A
    void rotate(vector<int>& nums, int k) {
        for (int i = 0; i < k; ++i) {
            nums.insert(nums.begin(), nums[nums.size() - 1]);
            nums.pop_back();
        }
    }

Log in to reply
 

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