力扣-剑指Offer 61题 扑克牌中的顺子(C++)- unordered_set

题目链接:https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/
题目如下:
在这里插入图片描述

class Solution {
    
    
public:
    bool isStraight(vector<int>& nums) {
    
    
        unordered_set<int> uset;
        int small=14,big=0;

        for(auto e:nums){
    
    
            if(e==0) continue;
            else if(uset.count(e)>0){
    
    
                return false;
            }else{
    
    
                uset.insert(e);
                small=min(small,e);
                big=max(big,e);
            }
        }

        return (big-small)<=4;
    }
};

おすすめ

転載: blog.csdn.net/qq_40467670/article/details/121459075