Majority Element
来源:互联网 发布:淘宝首页全屏装修教程 编辑:程序博客网 时间:2024/04/24 02:45
题目描述:给定一个数组,输出出现次数超过数组长度半数的数字。
public class Solution { public int majorityElement(int[] num) { int halfLen = num.length/2; HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>(); for(int i:num) { int cnt = hashMap.get(i)==null?1:hashMap.get(i)+1; hashMap.put(i, cnt); if(halfLen < cnt) return i; } return 1; }}
0 0
- majority element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- majority element
- Majority Element
- Majority Element
- PadLock AES内核测试模块(1)
- 为什么使用。NET Framework
- iOS --- 自动化测试工具UIAutomation
- Unique Binary Search Trees java 实现
- My alias
- Majority Element
- java的库、包、编辑单元、类,以及系统库和第三方库的引用问题。
- Android_adb shell am/pm使用
- cudaMemcpy2D参数中pitch的含义
- 01(CodeforcesA水平)CQU新生周末狂欢赛D - Soft Drinking
- webview的远程注入问题
- Jquery<4>Jquery 事件操作
- 【C++11】新特性——auto的使用
- matlab 修改文件名