标签:描述 -- als ber 差值 g++ fga ++ i++
1 class Solution { 2 public: 3 bool IsContinuous( vector<int> numbers ) { 4 if(numbers.empty()) 5 return false; 6 int length = numbers.size(); 7 sort(numbers.begin(),numbers.end()); 8 int numberOfZero = 0; 9 int numberOfGap = 0; 10 //统计0的数目,和差值和,相等或者0的数目多则可以构成顺子 11 for(int i=0;i<length;i++) 12 { 13 if(numbers[i] == 0) 14 numberOfZero++; 15 } 16 int small = numberOfZero; 17 int big = small+1; 18 while(big < length) 19 { 20 if(numbers[small] == numbers[big]) 21 { 22 return false; 23 } 24 numberOfGap += numbers[big] - numbers[small] - 1; 25 small = big; 26 big++; 27 } 28 return (numberOfZero>=numberOfGap)?true:false; 29 } 30 };
标签:描述 -- als ber 差值 g++ fga ++ i++
原文地址:http://www.cnblogs.com/qqky/p/7069221.html