#coding: utf-8
def judgeSequence(sequence):
"""
"""
length = len(sequence)
count_zero = 0
count_gap = 0
# 统计大小王的个数
for i in range(length):
if sequence[i] == 0:
count_zero = count_zero + 1
# 排序方便统计间隔
sequence.sort()
# 统计sequence中的前后两个数的跨度大小
for i in range(count_zero + 1, length):
if sequence[i] == sequence[i - 1]:
return False
count_gap = count_gap + sequence[i] - sequence[i - 1] - 1
if count_gap <= count_zero:
return True
return False
if __name__ == "__main__":
sequence = [0, 1, 3, 4, 0]
print("this sequence is %s, and judge whether is a sequence: [%s]" % (sequence, judgeSequence(sequence)))
sequence = [1, 3, 4, 2]
print("this sequence is %s, and judge whether is a sequence: [%s]" % (sequence, judgeSequence(sequence)))
sequence = [1, 3, 4, 2, 0]
print("this sequence is %s, and judge whether is a sequence: [%s]" % (sequence, judgeSequence(sequence)))
sequence = [1, 3, 4, 2, 6]
print("this sequence is %s, and judge whether is a sequence: [%s]" % (sequence, judgeSequence(sequence)))
sequence = [1, 3, 4, 0, 7]
print("this sequence is %s, and judge whether is a sequence: [%s]" % (sequence, judgeSequence(sequence)))