Return a new array with the numbers of nums in reverse order. Do not change nums.
reversed(new int[] {1, 2, 3, 4}) returns {4, 3, 2, 1}.
8 strips: V1 to V8
} V1return result; V2result[i] = nums[nums.length - i]; V3for (int i = 0; i < nums.length; i++) { V4int[] result = new int[nums.length]; V5result[i] = nums[nums.length - 1 - i]; V6public static int[] reversed(int[] nums) { V7} V8Order: V7, V5, V4, V6, V8, V2, V1. Extra: V3
public static int[] reversed(int[] nums) {
int[] result = new int[nums.length];
for (int i = 0; i < nums.length; i++) {
result[i] = nums[nums.length - 1 - i];
}
return result;
} Extra strip: result[i] = nums[nums.length - i];. When i is 0, nums[nums.length] is one past the last index, so it throws an ArrayIndexOutOfBoundsException.