Wins the offer - 71 straight playing cards

Title Description

LL particularly good mood today, because he bought a deck of cards and found that there actually has two king, two small king (the deck was originally 54 ^ _ ^) ... he randomly drawn from the five brand, wanted to Cece own luck, see if you can be able to get straight, if able to get it, he decided to buy a sports lottery, hey! ! "Red A, 3 of spades, Wang, King, square piece 5", "Oh My God!" Straight ..... LL is not happy, he thought, decides \ Amy can be seen as any number, and regarded as A 1, J is 11, Q is 12, K 13. The above five cards can become "1,2,3,4,5" (king size and 2, respectively seen as 4), "So Lucky!". LL decided to buy sports lottery friends. Now, I ask you to use this piece of card simulate the above procedure, and then tell us how LL luck, if the card can be composed of straight to output true, otherwise it will output false. For convenience, you can think of king size is 0.
 
answer:
  Counting the number of king size and number of the card difference determined whether equal.
 
  
 1 class Solution {
 2 public:
 3     bool IsContinuous(vector<int> numbers) {
 4         if (numbers.size() < 1)return false;
 5         sort(numbers.begin(), numbers.end());
 6         int zerosN = 0, lostN = 0;
 7         for (int i = 0; i < numbers.size(); ++i)
 8         {
 9             if (numbers[i] == 0)zerosN++;//King size calculated number 
10              the else  IF (I> 0 && Numbers [I] == Numbers [I - . 1 ]) return  to false ; // occurs pair 
. 11              the else  IF (I> 0 ) + = lostN Numbers [I] - numbers [I - . 1 ] - . 1 ; // number of cards spanned 
12 is          }
 13 is          return zerosN> = lostN;
 14      }
 15 };

 

Guess you like

Origin www.cnblogs.com/zzw1024/p/11709090.html