扑克牌顺子
扑克牌顺子
http://www.nowcoder.com/questionTerminal/762836f4d43d43ca9deb273b3de8e1f4
对数组排序,计算0的个数; 除0以外的子序列有相同的数返回False, 否则计算总间隙,等于0 ,或者,小于等于0的个数,则返回True。
# -*- coding:utf-8 -*- class Solution: def IsContinuous(self, nums): # write code here if len(nums)<=4: return False nums.sort() zeros = nums.count(0) gap = 0 for i in range(zeros, len(nums)-1): if nums[i+1]-nums[i] == 0: return False gap += nums[i+1] - nums[i] - 1 return True if gap == 0 or gap <= zeros else False