Skip to content

Instantly share code, notes, and snippets.

@OmarKRostom
Created December 29, 2019 13:51
Show Gist options
  • Save OmarKRostom/d9d404698eb0f5407e3b136b9a5a8827 to your computer and use it in GitHub Desktop.
Save OmarKRostom/d9d404698eb0f5407e3b136b9a5a8827 to your computer and use it in GitHub Desktop.
A way to solve shift numbers in java
public static int[] shiftNums(int[] nums, int shiftCount) {
int[] numsClone = nums.clone();
while (shiftCount > 0) {
int itemToBeShifted = nums[nums.length - 1];
for (int i = 0; i < nums.length - 1; i++) {
nums[i + 1] = numsClone[i];
}
nums[0] = itemToBeShifted;
numsClone = nums.clone();
shiftCount--;
}
return nums;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment