"Standard" C++ solution, 1 line, O(n) time


  • 0
    L
    class Solution {
    public:
        void rotate(vector<int>& nums, int k) {
            std::rotate(nums.rbegin(), nums.rbegin() + k % nums.size(), nums.rend());
        }
    };
    

Log in to reply
 

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