> For the complete documentation index, see [llms.txt](https://ryukiedev.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ryukiedev.gitbook.io/wiki/shu-ju-jie-gou-yu-suan-fa/jian-zhi-offerswift/61.-pu-ke-pai-zhong-de-shun-zi.md).

# 61.扑克牌中的顺子

### 一、 题目

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

示例 1:

输入: \[1,2,3,4,5]

输出: True &#x20;

示例 2:

输入: \[0,0,1,2,5]

输出: True

限制：

数组长度为 5

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

来源：力扣（LeetCode）

链接：<https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof>

著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。

### 二、 解法

```
func isStraight(_ nums: [Int]) -> Bool {
    var zeroCount = 0
    var last: Int?
    
    for i in nums.sorted() {
        if i == 0 {
            zeroCount += 1
        }
        else if let l = last {
            let deta = i - l
            if deta > 0 {
                zeroCount -= (deta - 1)
                last = i
            }
            else {
                return false
            }
        }
        else {
            last = i
        }
        
        if zeroCount < 0 {
            return false
        }
    }
    
    return true
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ryukiedev.gitbook.io/wiki/shu-ju-jie-gou-yu-suan-fa/jian-zhi-offerswift/61.-pu-ke-pai-zhong-de-shun-zi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
