My solution in 24 ms easy to understand


  • 0
    R
    class Solution {
    public:
    void rotate(vector<int>& nums, int k) {
        if(k>nums.size())k=k%nums.size(); 
            std::reverse(nums.end()-k,nums.end());
           std::reverse(nums.begin(),(nums.end()-k));
           std::reverse(nums.begin(),nums.end());
    }};

Log in to reply
 

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