是否扑克牌中的顺子

从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的。2~10为数字本身,A为1,J为11,Q为12,K为13,而大、小王为 0 ,可以看成任意数字。A 不能视为 14。

示例 1:

输入: [1,2,3,4,5]
输出: True
 

示例 2:

输入: [0,0,1,2,5]
输出: True
 

限制:

数组长度为 5 

数组的数取值为 [0, 13] .

<font size="9">来源:力扣(LeetCode)</font>


"""
@author: WowlNAN
@github: https://github.com/WowlNAN
@created: 2020-08-01 04:35PM
"""

class Solution:
    def isStraight(self, nums: List[int]) -> bool:
        a=nums
        a=sorted(a)
        l=len(a)
        i=1
        b=a[0]
        c=0
        d=0
        if b==0:
            c+=1
        while i<l:
            if a[i]==0:
                c+=1
            elif b<a[i]:
                if b!=0 and b+1<a[i]:
                    d+=a[i]-b-1
            elif b==a[i]:
                if b!=0:
                    return False
            b=a[i]
            i+=1
        if c<d:
            return False
        else:
            return True

猜你喜欢

转载自blog.csdn.net/qq_21264377/article/details/107732918