标签:
1 bool IsContinous(int* numbers,int length) 2 { 3 if(numbers==NULL||length<1) 4 return false; 5 qsort(numbers,length,sizeof(int),compare); 6 int numberOfZero=0; 7 int numberOfGap=0; 8 9 //统计数组中0的个数 10 for(int i=0;i<length&&numbers[i]==0;++i) 11 ++numberOfZero; 12 13 //统计数组中的间隔数目 14 int small=numberOfZero; 15 int big=small+1; 16 while(big<length) 17 { 18 //如果两个数相等,有对子,不可能是顺子 19 if(numbers[small]==numbers[big]) 20 return false; 21 22 numberOfGap +=number[big]-number[small]-1; 23 small=big; 24 ++big; 25 } 26 return (numberOfGap>numberOfZero) ? false : true; 27 } 28 29 int compare(const void *arg1,const void * arg2) 30 { 31 return *(int*)arg1 - *(int*)arg2; 32 } 33
标签:
原文地址:http://www.cnblogs.com/wxdjss/p/5565075.html