Efficient way to find missing elements in an integer sequence

前端 未结 16 1355
鱼传尺愫
鱼传尺愫 2020-12-01 04:32

Suppose we have two items missing in a sequence of consecutive integers and the missing elements lie between the first and last elements. I did write a code that does accomp

16条回答
  •  一生所求
    2020-12-01 05:30

    >>> l = [10,11,13,14,15,16,17,18,20]
    >>> [l[i]+1 for i, j in enumerate(l) if (l+[0])[i+1] - l[i] > 1]
    [12, 19]
    

提交回复
热议问题