O(n) time and O(1) space solution
The idea is to rotate using reversal.\n1. divide the array into two parts.\n2. reverse first part\n3. reverse second part\n4. reverse whole array\n\n    /\n    
The idea is to rotate using reversal.\n1. divide the array into two parts.\n2. reverse first part\n3. reverse second part\n4. reverse whole array\n\n    /**\n     * rotate right an array\n     * nums      : pointer to array to be rotated\n     * numsSize  : length of array\n     * k         : distance of rotation\n     */ \n    void rotate(int* nums, int numsSize, int k) {\n        k = k % numsSize;\n        if (k == 0) return;\n        if (numsSize <= 1) return;\n        \n        //divide the array into 2 part\n        int lengthFirstPart = numsSize - k;\n        //reverse first part\n        reverse(nums, lengthFirstPart);\n        //reverse second part\n        reverse(&nums[lengthFirstPart], numsSize - lengthFirstPart);\n        //reverse everything\n        reverse(nums, numsSize);\n    }\n    \n    /**\n     * reverse array\n     * nums      : pointer to array to be reversed\n     * numsSize  : length of array\n     */ \n    void reverse(int* nums, int numsSize){\n        int mid = numsSize / 2;\n        int temp;\n        for(int i = 0; i < mid; i++){\n            temp = nums[i];\n            nums[i] = nums[numsSize - 1 - i];\n            nums[numsSize - 1 - i] = temp;\n        }\n    }
[]