编程之美中的思路。
int MoreThanHalf(int A[], int length) { if(A == NULL || length < 1) return 0; int result = A[0]; int times = 1; for(int i = 1; i < length; ++i) { if(times == 0){ result = A[i]; times = 1; }else if(A[i] == result){ ++times; }else --times; } return result; }