// test20.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<string.h>
#include<deque>
using namespace std;
class Solution {
public:
bool IsContinuous(vector<int> numbers) {
int min = 0, max = 0, count_0 = 0;
for (int i = 0;i < numbers.size();++i)
{
if (numbers[i] == 0)
{
++count_0;
continue;
}
else
{
if (min == 0)
min = numbers[i];
else if (min > numbers[i])
min = numbers[i];
else {}
if (max == 0)
max = numbers[i];
else if (max < numbers[i])
max = numbers[i];
else{}
}
}
if (count_0 == 4) return true;
if (max == min) return false;
if (max - min>4) return false;
return true;
}
};
int main()
{
Solution so;
vector<int> numbers = { 1,2,3,4,5 };
/* bool result=so.IsContinuous(numbers);
cout <<"result:"<< result << endl;*/
bool result = so.IsContinuous(numbers);
cout << "result:" << result << endl;
cout << endl;
return 0;
}
// test20.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<string.h>
#include<deque>
using namespace std;
class Solution {
public:
bool IsContinuous(vector<int> numbers) {
int min = 0, max = 0, count_0 = 0;
for (int i = 0;i < numbers.size();++i)
{
if (numbers[i] == 0)
{
++count_0;
continue;
}
else
{
if (min == 0)
min = numbers[i];
else if (min > numbers[i])
min = numbers[i];
else {}
if (max == 0)
max = numbers[i];
else if (max < numbers[i])
max = numbers[i];
else{}
}
}
if (count_0 == 4) return true;
if (max == min) return false;
if (max - min>4) return false;
return true;
}
};
int main()
{
Solution so;
vector<int> numbers = { 1,2,3,4,5 };
/* bool result=so.IsContinuous(numbers);
cout <<"result:"<< result << endl;*/
bool result = so.IsContinuous(numbers);
cout << "result:" << result << endl;
cout << endl;
return 0;
}