[剑指 offer] JT45---Poker card straight (whether it is straight or not depends on the length of the first and last difference!)

The forty-fifth question of the sword finger offer

The topic is as follows

Insert picture description here

Idea and code

First find out the largest and smallest numbers. If the difference between them is greater than the length of the card, it won’t be possible, because the universal card can’t be filled.
If it is equal to the length, then it happens.
If it is less than the length, then there is a universal card. Just make up at will!

class Solution {
    
    
public:
    bool IsContinuous( vector<int> numbers ) {
    
    
        int record[14]={
    
    0},maxn=-1,minn=14;
        for(auto a:numbers){
    
    
            if(a==0) continue;
            maxn=max(maxn,a);
            minn=min(minn,a);
            if(++record[a]>1) return false;
        }
        return maxn-minn<numbers.size();
    }
};

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42136832/article/details/115056501