腾讯的一道面试题

if __name__ == '__main__':
    l=[0,1,3,10,12]
    result=[]
    max=99
    for i in range(1,len(l)):
        if(l[i]-l[i-1] !=1):
            pre = l[i-1]+1
            next = l[i]-1
            if(pre == next):
                result.append(str(pre))
            else:
                result.append(str(pre)+'-'+str(next))
        if i==len(l)-1:
            result.append(str(l[i]+1))
        else:
            result.append(str(l[i]+1)+'-'+str(max))
    print(result)

相关文章:

  • 2022-12-23
  • 2021-07-02
  • 2021-09-02
  • 2021-06-24
  • 2021-10-03
猜你喜欢
  • 2022-02-03
  • 2021-08-07
  • 2021-06-11
  • 2021-08-29
  • 2021-11-08
  • 2021-04-09
  • 2021-06-25
相关资源
相似解决方案