C++ / Java Simple and Clean, Very Efficient Solutions
C++:\n\nclass Solution {\npublic:\n    void reverse_range(vector<int>& nums, int i, int j) {\n        while (i < j)\n            swap(nums[i++], nums[j--]);\n  
**C++:**\n```\nclass Solution {\npublic:\n    void reverse_range(vector<int>& nums, int i, int j) {\n        while (i < j)\n            swap(nums[i++], nums[j--]);\n    }\n    \n    void rotate(vector<int>& nums, int k) {\n        k = k % nums.size();\n        if (nums.size() <= 1) return;\n        \n        reverse_range(nums, 0, nums.size()-1);\n        reverse_range(nums, k, nums.size()-1);\n        reverse_range(nums, 0, k-1);\n    }\n};\n```\n****\n**Java:**\n```\nclass Solution {\n    void reverse_range(int[] nums, int i, int j) {\n        while (i < j) {\n            int temp = nums[i];\n            nums[i] = nums[j];\n            nums[j] = temp;\n            i++;\n            j--;\n        }\n    }\n    public void rotate(int[] nums, int k) {\n        k = k % nums.length;\n        if (nums.length <= 1) return;\n        \n        reverse_range(nums, 0, nums.length-1);\n        reverse_range(nums, k, nums.length-1);\n        reverse_range(nums, 0, k-1);\n    }\n}\n```\n**Like it? please upvote!**
['C', 'Java']