剑指offer---扑克牌的顺子

class Solution 
{
public:
    bool IsContinuous(vector<int> numbers)
    {
        int max_num = -1;
        int min_num = 14;
        int in_size = numbers.size();
        if (in_size != 5)    return false;
        for (int i = 0; i < in_size; ++i)
        {
            max_num = max(numbers[i], max_num);
            
        }
        for (int i = 0; i < in_size; ++i)
        {
            if ((numbers[i] < min_num) && (numbers[i] != 0))
            {
                min_num = numbers[i];
            }
        }

        int flag = 0;
        for (int i = 0; i < in_size; ++i)
        {
            for (int j = (i + 1); j < in_size; ++j)
            {
                if ((numbers[i] == numbers[j]) && (numbers[i] != 0))
                {
                    flag = 1;
                    
                }
            }
        }

        if( (max_num - min_num < 5)&&(flag==0))
        {
            return true;
            
        }
        else return false;
        
    }
};

 

posted @ 2017-08-04 10:57  双马尾是老公的方向盘  阅读(127)  评论(0编辑  收藏  举报