很容易想到的思路
扑克牌顺子
http://www.nowcoder.com/questionTerminal/762836f4d43d43ca9deb273b3de8e1f4
排序后从大到小每个元素之间差值(除了1)小于数组中0的数量即可组成顺子,我老赌怪了。
-- coding:utf-8 --
class Solution:
def IsContinuous(self, numbers):
# write code here
numbers.sort()
lst = numbers[:]
lst = list(filter(lambda x: x != 0, lst))
if len(set(lst)) != len(lst) or len(numbers) != 5:
return False
sub = 0
for i in range(len(lst) - 1, 0, -1):
sub += lst[i] - lst[i-1] - 1
if len(numbers)-len(lst) >= sub :
return True
return False