【Python】【难度:简单】Leetcode 面试题61. 扑克牌中的顺子

从扑克牌中随机抽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] .

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

class Solution(object):
    def isStraight(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        nums=[i for i in nums if i]
        return len(nums)==len(set(nums)) and max(nums)-min(nums)<5     

执行结果:

通过

显示详情

执行用时 :28 ms, 在所有 Python 提交中击败了31.09%的用户

内存消耗 :12.7 MB, 在所有 Python 提交中击败了100.00%的用户

原创文章 105 获赞 0 访问量 1679

猜你喜欢

转载自blog.csdn.net/thomashhs12/article/details/106006179