'''
https://blog.csdn.net/fuxuemingzhu/article/details/79702017
我们需要做三件事:
1 给数字排序
2 计算排序后的数字的零的个数count
3 计算数字之间的gap,相邻数字之间为number[i+1]-num[i]-1
4 如果count>=gap,那么可以构成同花顺
'''
# -*- coding:utf-8 -*-
class Solution:
def IsContinuous(self, numbers):
# if not numbers: return False
if not numbers or len(numbers)!=5 :
return False
for i in range(len(numbers)):
if numbers[i]<0 or numbers[i]>13:
return False
numbers.sort()
zeros = numbers.count(0)
gaps = 0
small = zeros
big = small + 1
while big < len(numbers):
if numbers[small] == numbers[big]:
return False
gaps += numbers[big] - numbers[small] - 1
small = big
big += 1
return gaps <= zeros
if __name__ == '__main__':
numbers=[2,3,4,-1,0]
result=Solution().IsContinuous(numbers)
print(result)