其他分享
首页 > 其他分享> > 扑克牌中的顺子

扑克牌中的顺子

作者:互联网

class Solution {
public:
    bool IsContinuous( vector<int> numbers ) {
        if(numbers.size() == 0)return false;
        int count[14] = {0};//用来记录元素是否出现过
        int maxVal = -1;
        int minVal = 14;
        for(int i = 0; i < numbers.size(); i++){
            if(numbers[i] == 0)continue;
            if(count[numbers[i]]>0)return false;
            count[numbers[i]]++;
            if(numbers[i] > maxVal){
                maxVal = numbers[i];
            }
            if(numbers[i]<minVal){
                minVal = numbers[i];
            }
        }
        if(maxVal - minVal < 5){
            return true;
        }
        return false;
    }
};

  若满足顺子需要两个条件

1.除了0以外不能有重复数字。

2.最大值减最小值要小于5。

标签:count,maxVal,false,扑克牌,int,numbers,顺子
来源: https://www.cnblogs.com/icehole/p/12112978.html