Clean intuitive solution accepted as best submission in C


  • 0
    void rotate0(int* nums, int size)
    {
        for(int i = 0; i < size/2; i++)
        {
            int t = nums[i];
            nums[i] = nums[size-i-1];
            nums[size-i-1] = t;
        }
    }
    //AC - 8ms;
    void rotate(int* nums, int size, int k)
    {
        k %= size;
        rotate0(nums, size);
        rotate0(nums, k);
        rotate0(nums+k, size-k);
    }

Log in to reply
 

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