剑指 Offer 61. 扑克牌中的顺子https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof/
优雅写法
bool isStraight(vector<int>& nums) {
int maxVal = INT_MIN, minVal = INT_MAX;
unordered_set<int> s;
for (const int num : nums)
{
if (num == 0) // 跳过大小王
{
continue;
}
if (s.count(num)) // 出现重复数字
{
return false;
}
s.insert(num);
maxVal = max(maxVal, num);
minVal = min(minVal, num);
}
return maxVal - minVal < 5;
}