pagict
2013-12-27 11:28:09 +08:00
刚刚实现了一遍 欢迎各种来喷(bug 编码习惯)cpp
int maxCount(const int *nums, int length) {
int max=0;
int i=0;
int thisNum = nums[i];
int oldNum = thisNum;
while(i<length) {
while(i>=0 && nums[i]==thisNum) i--;// retrospect
i++;
i=i+max;
if (nums[i]==thisNum) { // a more number
max++;
while(i<length && nums[i]==thisNum) i++, max++; // to the boundary
max--;
}
oldNum = thisNum; // save the previous number to return
thisNum=nums[i]; // skip some fewer numbers, update thisNum
}
return oldNum;
}