61 扑克牌的顺子

class Solution:
    def isContinuous(self,A):
        sortlist = []
        numofJ = 0
        for i in A:
            if (i in sortlist) & (i != 'Joker'):
                return False

            if i =='A':
                sortlist.append(1)
            elif i == 'J':
                sortlist.append(11)
            elif i == 'Q':
                sortlist.append(12)
            elif i == 'K':
                sortlist.append(13)
            elif i == 'Joker':
                numofJ +=1
            else:
                sortlist.append(i)

        sortlist.sort()

        gap = 0
        left = sortlist[0]
        right = sortlist[-1]
        while left < right:
            if left + 1 in sortlist:
                left += 1
            else:
                left +=1
                gap +=1

        if gap <= numofJ:
            return True
        else:
            return False



        
            



s = Solution()
S = ['Joker',1,3,4,5]
print(s.isContinuous(S))

你可能感兴趣的:(61 扑克牌的顺子)