双层for循环遍历数组,第一层循环从前往后遍历数组,第二层for循环从后往前遍历数组
public class Solution { public int MoreThanHalfNum_Solution(int [] array) { int len = array.length; for(int i=0;i<len;i++){ int temp = 1; for(int j=len-1;j>i;j--){ if(array[i] == array[j]){ temp += 1; } } if(temp > len/2){ return array[i]; } } return 0; } }