It's the first even-index number not followed by the same number.
def single_non_duplicate(nums)
nums[2 * (0..nums.size/2).bsearch { |i| nums[2*i] != nums[2*i+1] }]
end
Edit: Found an even shorter way.
It's the first even-index number not followed by the same number.
def single_non_duplicate(nums)
nums[2 * (0..nums.size/2).bsearch { |i| nums[2*i] != nums[2*i+1] }]
end
Edit: Found an even shorter way.