【剑指offer】扑克牌顺子

运行时间:24ms

占用内存:5732k

排序后判断的

# -*- coding:utf-8 -*-
class Solution:
    def IsContinuous(self, numbers):
        # write code here
        if not numbers:
            return None
        numbers.sort()
        print(numbers)
        cntw = 0
        n = len(numbers)
        for i in range(n):
            if numbers[i] == 0:
                cntw += 1
            elif i>0 and numbers[i-1]!=0:
                if numbers[i]==numbers[i-1]:
                    return False
                elif numbers[i]-numbers[i-1]>1:
                    if cntw < numbers[i]-numbers[i-1]-1:
                        return False
                        break
                    else:
                        cntw -= numbers[i]-numbers[i-1]-1
        return True

大佬们回答出bitmap排序思想,没咋看懂

你可能感兴趣的:(leetcode)