mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 17:24:18 +00:00
Update 61. 扑克牌顺子.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+9
-10
@@ -2,7 +2,7 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[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)
|
||||
[Leetcode](https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof/)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@@ -14,24 +14,23 @@
|
||||
## 解题思路
|
||||
|
||||
```java
|
||||
public boolean isContinuous(int[] nums) {
|
||||
|
||||
if (nums.length < 5)
|
||||
public boolean checkDynasty(int[] places) {
|
||||
if (places == null || places.length < 5)
|
||||
return false;
|
||||
|
||||
Arrays.sort(nums);
|
||||
Arrays.sort(places);
|
||||
|
||||
// 统计癞子数量
|
||||
int cnt = 0;
|
||||
for (int num : nums)
|
||||
if (num == 0)
|
||||
for (int place : places)
|
||||
if (place == 0)
|
||||
cnt++;
|
||||
|
||||
// 使用癞子去补全不连续的顺子
|
||||
for (int i = cnt; i < nums.length - 1; i++) {
|
||||
if (nums[i + 1] == nums[i])
|
||||
for (int i = cnt; i < places.length - 1; i++) {
|
||||
if (places[i + 1] == places[i])
|
||||
return false;
|
||||
cnt -= nums[i + 1] - nums[i] - 1;
|
||||
cnt -= places[i + 1] - places[i] - 1;
|
||||
}
|
||||
|
||||
return cnt >= 0;
|
||||
|
||||
Reference in New Issue
Block a user