从若干副扑克牌中随机抽 5 张牌,判断是不是一个顺子,即这5张牌是不是连续的。2~10为数字本身,A为1,J为11,Q为12,K为13,而大、小王为 0 ,可以看成任意数字。A 不能视为 14。
示例 1:
输入: [1,2,3,4,5]
输出: True
示例 2:
输入: [0,0,1,2,5]
输出: True
public class Solution {
public bool IsStraight(int[] nums) {
var cnt=new int[14];
int min=14;
int max=0;
foreach(var num in nums)
{
if(num>0)
{
if(cnt[num]>0)
{
return false;
}
cnt[num]++;
max=Math.Max(max,num);
min=Math.Min(min,num);
}
}
return max-min<=4;
}
}
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。