diff --git a/notes/61. 扑克牌顺子.md b/notes/61. 扑克牌顺子.md index 9948e0dc..002d695e 100644 --- a/notes/61. 扑克牌顺子.md +++ b/notes/61. 扑克牌顺子.md @@ -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;