Created
December 29, 2019 13:51
-
-
Save OmarKRostom/d9d404698eb0f5407e3b136b9a5a8827 to your computer and use it in GitHub Desktop.
A way to solve shift numbers in java
This file contains 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
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