剑指offer 61

题目描述

五张牌,其中大小鬼为癞子,牌面大小为 0。判断是否能组成顺子。

题解

# -*- coding:utf-8 -*-
class Solution:
    def IsContinuous(self, numbers):
        # write code here

        if len(numbers) == 0:
            return False

        cnt = 0
        numbers = sorted(numbers)
        for i in numbers:
            if i == 0:
                cnt = cnt+1

        for i in range(cnt,len(numbers)-1):
            if numbers[i] == numbers[i+1]:
                return False
            cnt = cnt - (numbers[i+1]-numbers[i]-1)
        return cnt>=0

你可能感兴趣的:(编码)