2019-11-02 12:07:41 +08:00
|
|
|
# 61. 扑克牌顺子
|
|
|
|
|
2019-11-03 23:57:08 +08:00
|
|
|
## 题目链接
|
|
|
|
|
2022-01-07 09:00:01 +00:00
|
|
|
[NowCoder](https://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4?tpId=13\&tqId=11198\&tPage=1\&rp=1\&ru=/ta/coding-interviews\&qru=/ta/coding-interviews/question-ranking\&from=cyc\_github)
|
2019-11-02 12:07:41 +08:00
|
|
|
|
|
|
|
## 题目描述
|
|
|
|
|
|
|
|
五张牌,其中大小鬼为癞子,牌面为 0。判断这五张牌是否能组成顺子。
|
|
|
|
|
2022-01-07 09:00:01 +00:00
|
|
|
\
|
2019-11-02 12:07:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
## 解题思路
|
|
|
|
|
|
|
|
```java
|
|
|
|
public boolean isContinuous(int[] nums) {
|
|
|
|
|
|
|
|
if (nums.length < 5)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Arrays.sort(nums);
|
|
|
|
|
|
|
|
// 统计癞子数量
|
|
|
|
int cnt = 0;
|
|
|
|
for (int num : nums)
|
|
|
|
if (num == 0)
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
// 使用癞子去补全不连续的顺子
|
|
|
|
for (int i = cnt; i < nums.length - 1; i++) {
|
|
|
|
if (nums[i + 1] == nums[i])
|
|
|
|
return false;
|
|
|
|
cnt -= nums[i + 1] - nums[i] - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt >= 0;
|
|
|
|
}
|
|
|
|
```
|