如果这个数的数量超过了一半,必然越过中线。
public class Solution {
public int MoreThanHalfNum_Solution(int [] array) {
int x = array[array.length / 2];
int count = 0;
for(int cp : array) {
if(x == cp)count++;
}
if(count > array.length / 2) {
return x;
}
return 0;
}
}