169. Majority Element Poison 2022-05-03 1234567891011121314class Solution { public int majorityElement(int[] nums) { int majorityElement = 0, votes = 0; for (int num : nums) { if (votes == 0) { majorityElement = num; } votes += num == majorityElement ? 1 : -1; } return majorityElement; }} References169. Majority Element剑指 Offer 39. 数组中出现次数超过一半的数字面试题 17.10. 主要元素