Created
January 13, 2022 05:31
-
-
Save heemoe/005c5283e082728cc16adc03066002ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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