Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 521 Bytes

makeMiddle.md

File metadata and controls

21 lines (15 loc) · 521 Bytes

makeMiddle

Given an array of ints of even length, return a new array length 2 containing the middle two elements from the original array. The original array will be length 2 or more.

makeMiddle([1, 2, 3, 4]) → [2, 3]
makeMiddle([7, 1, 2, 3, 4, 9]) → [2, 3]
makeMiddle([1, 2]) → [1, 2]

Solution:

public int[] makeMiddle(int[] nums) {
  return new int[]{nums[nums.length/2-1],nums[nums.length/2]};
}

codingbat

< back to readme