3 ms·
A = [1, 2, 4, 5, 7] A_s = sorted(A) b = A_s[0] for a in A_s[1:]: if a - b > 1: print b + 1 break else: b = a else: print '
by kghose 12y ago
A = [1, 2, 4, 5, 7]
A_s = sorted(A)
b = A_s[0]
for a in A_s[1:]:
if a - b > 1:
print b + 1
break
else:
b = a
else:
print 'No missing element'
Trying to be more Pythonic:
def test(l):
l_s = sorted(l)
print [l0 + 1 for l1, l0 in zip(l_s[1:], l_s[:-1]) if l1 - l0 > 1]
- abhinavk 12y agoBut the code is not competitive.
- ericfrederich 12y agoSorting is not O(N), at best it is O(NlogN)