思路:看是否连续就是看中间缺少的部分能否用大小王,即0来填充,因此只需要比较0的个数和中间缺少的个数就行了,如果中间缺少的比0的数目多,即大小王的个数不足以将缺少的填充,那么就不连续了
# -*- coding:utf-8 -*-
class Solution:
def IsContinuous(self, numbers):
# write code here
if numbers == []:
return False
numbers.sort()
cnt_0 = 0
cnt = 0
for i in range(len(numbers)-2,-1, -1):
if numbers[i] == 0:
cnt_0 += 1
else:
if numbers[i+1] == numbers[i]:
return False
else:
cnt += (numbers[i+1] - numbers[i] -1)
if cnt > cnt_0:
return False
else:
return True