You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this “outlier” N.
从一组偶数里面找出唯一的一个奇数,或从一组奇数里面找出唯一的一个偶数。
源码:
def find_outlier(integers):
for i in range(len(integers)-1):
if integers[i]%2 != integers[i+1]%2:
if integers[i-1]%2 == integers[i+1]%2:
return integers[i]
else:
return integers[i+1]