# 扑克牌顺子

![last modify](https://img.shields.io/static/v1?label=last%20modify\&message=2022-10-14%2014%3A59%3A33\&color=yellowgreen\&style=flat-square) [![](https://img.shields.io/static/v1?label=\&message=%E7%AE%80%E5%8D%95\&color=yellow\&style=flat-square)](https://imhuay.gitbook.io/studies/algorithms/..#简单) [![](https://img.shields.io/static/v1?label=\&message=%E7%89%9B%E5%AE%A2\&color=green\&style=flat-square)](https://imhuay.gitbook.io/studies/algorithms/..#牛客) [![](https://img.shields.io/static/v1?label=\&message=%E6%A8%A1%E6%8B%9F\&color=blue\&style=flat-square)](https://imhuay.gitbook.io/studies/algorithms/..#模拟)

> [扑克牌顺子\_牛客题霸\_牛客网](https://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4)

**问题简述**

```
现在有2副扑克牌，从扑克牌中随机五张扑克牌，我们需要来判断一下是不是顺子。
有如下规则：
1. A为1，J为11，Q为12，K为13，A不能视为14
2. 大、小王为 0，0可以看作任意牌
3. 如果给出的五张牌能组成顺子（即这五张牌是连续的）就输出true，否则就输出false。
4.数据保证每组5个数字，每组最多含有4个零，数组的数取值为 [0, 13]
```

**思路**

* 不能有重复牌；
* 最大和最小之间的差小于等于 4；

<details>

<summary><strong>Python</strong></summary>

```python
class Solution:
    def IsContinuous(self , arr: List[int]) -> bool:
        # write code here
        
        book = set()
        mx, mi, cnt0 = 1, 13, 0
        
        for x in arr:
            if x == 0:
                cnt0 += 1
                continue
            book.add(x)
            mx = max(mx, x)
            mi = min(mi, x)
        
        # 组成顺子的条件：没有重复牌，最大和最小的差小于等于 4
        return len(book) == 5 - cnt0 and mx - mi <= 4
```

</details>
