Randomly playing cards from the card 5, a determination is not straight, i.e., five cards are not continuous.
2 to 10 as the number itself, A is 1, J is 11, Q is 12, K 13, any number can be seen as the king size.
For convenience, the king size 0 are represented and assume the deck are two king size.
Sample 1
Input: [8,9,10,11,12]
Output: true
Sample 2
Input: [0,8,9,11,12]
Output: true
class Solution {
public:
bool isContinuous( vector<int> numbers ) {
int n = numbers.size();
if(n == 0) return false;
sort(numbers.begin(),numbers.end());
int zero = 0;
for(int i = 0;i < n;i++) {
if(numbers[i] == 0) {
zero++;
continue;
}
if(i >= 1 && numbers[i - 1] != 0){
int num = numbers[i] - numbers[i - 1];
if(num == 1) continue;
else if(num > 1 && zero >= num - 1) {
zero -= num - 1;
}
else return false;
}
}
return true;
}
};