(Easy) Rotate Array - LeetCode
Description:
Solution:
class Solution { public void rotate(int[] nums, int k) { List<Integer> arr = new ArrayList<Integer>(); for(int i = 0; i<nums.length;i++){ arr.add(nums[i]); } while(k>0){ int tmp =arr.get(nums.length-1); arr.add(0,tmp); k = k-1; } for(int i = 0; i<nums.length; i++){ nums[i] = arr.get(i); } } }