摘要:
题目链接 代码 /** * 摩尔投票 * 用投票抵消的思路来解题,如果当前的数字和下一个数字相等,那么可以抵消的票数 * +1,如果不相等,那么-1 * */ public int majorityElement(int[] nums) { int ans = 0, votes = 0; for ( 阅读全文
摘要:
题目链接 代码 class Solution { public List<Integer> majorityElement(int[] nums) { // 创建返回值 List<Integer> res = new ArrayList<>(); if (nums == null || nums.l 阅读全文