Skip to content

Instantly share code, notes, and snippets.

@heemoe
Created January 13, 2022 05:31
Show Gist options
  • Save heemoe/005c5283e082728cc16adc03066002ea to your computer and use it in GitHub Desktop.
Save heemoe/005c5283e082728cc16adc03066002ea to your computer and use it in GitHub Desktop.
class javachallenge {
public static int[] rotate(int[] arr) {
int k = 2;
int[] nums = arr;
int length = nums.length;
int left = length - (k % length);
int right = k % length;
int[] newArr = new int[length];
System.arraycopy(nums, left, newArr, 0, right);
System.arraycopy(nums, 0, newArr, right, left);
System.arraycopy(newArr, 0, nums, 0, length);
return newArr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment