The problem I am referring to is here
So basically it's about shifting an array of ints 1 position to the left and relocating the lost first int in the start of the array to the last position at the right:
\$\mathrm{shiftLeft}(\{6, 2, 5, 3\}) → \{2, 5, 3, 6\}\$
\$\mathrm{shiftLeft}(\{1, 2\}) → \{2, 1\}\$
\$\mathrm{shiftLeft}(\{1\}) → \{1\}\$
Please feel free to review the code below:
public int[] shiftLeft(int[] nums) {
for(int i = 0, start = 0; i < nums.length; i++)
{
if(i == 0)
start = nums[i];
if(i == (nums.length -1))
{
nums[i] = start;
break;
}
nums[i] = nums[i + 1];
}
return nums;
}
Also I would like to get rid of the variable start and try to solve it only using the loop iterator i, any suggestions are welcome.