import java.util.HashMap; import java.util.Map; public class Solution { public int MoreThanHalfNum_Solution(int [] array) { Map<Integer, Integer> map = new HashMap<>(); int ans = 0; for (int i : array) { map.put(i, map.getOrDefault(i, 0) + 1); if (map.get(i) > array.length / 2) { ans = i; break; } } return ans; } }