rotateLeft3([1, 2, 3]) → [2, 3, 1]
rotateLeft3([5, 11, 9]) → [11, 9, 5]
rotateLeft3([7, 0, 0]) → [0, 0, 7]
Answer 1:
public int[] rotateLeft3(int[] nums) {Answer 2:
return new int[] {nums[1],nums[2],nums[0]};
}
public int[] rotateLeft3(int[] nums) {
int[] tempArr = new int[3];
tempArr[0] = nums[1];
tempArr[1] = nums[2];
tempArr[2] = nums[0];
return tempArr;
}
Reference
http://www.javaproblems.com/2012/12/coding-bat-java-array-1-rotateleft3.html
No comments :
Post a Comment