题解 | #出现次数大于等于数组长度一半的数#
出现次数大于等于数组长度一半的数
http://www.nowcoder.com/questionTerminal/919c2e0f64874d6d9797b14340674456
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = in.nextInt();
}
System.out.println(helper(nums));
}
public static int helper(int[] nums) {
Arrays.sort(nums);
return nums[nums.length/2];
}
}