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