The use of simple swapping, with an explanation. 0ms, 100% faster
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nDivide the array into t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nDivide the array into two parts, one ranging from 0 to n-k-1 and the other ranging from n-k to n-1. Afterward, reverse the first and second parts of the array and finally reverse the entire array to obtain the result\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public void rotate(int[] nums, int k) {\n        int n=nums.length;\n        k=k%n;\n        flip(nums,0,n-k-1);\n        flip(nums,n-k,n-1);\n        flip(nums,0,n-1);\n        \n    }\n    public void flip(int[] arr,int s,int e)\n    {\n        while(s<e)\n        {\n            int temp=arr[s];\n            arr[s]=arr[e];\n            arr[e]=temp;\n            s++;\n            e--;\n        }\n    }\n}\n```
['Java']