就是暴力从头遍历
/** * * @param numbers int整型一维数组 * @param numbersLen int numbers数组长度 * @return int整型 */ int MoreThanHalfNum_Solution(int* numbers, int numbersLen ) { // write code here int i, j, count, jackpot; if(numbersLen == 1) jackpot = numbers[0]; for(i = 0; i < numbersLen - 1; i ++) { count = 1; for(j = i + 1; j < numbersLen; j++) { if(numbers[i] == numbers[j]) { count++; jackpot = numbers[i]; } } if(count > (numbersLen / 2 )) { break; } } return jackpot; }