169. Majority Element (9月8日)
来源:互联网 发布:淘宝保证金能退吗 编辑:程序博客网 时间:2024/06/05 20:22
169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
You may assume that the array is non-empty and the majority element always exist in the array.
最便捷最容易想到的莫非就是map了。
先上map的代码
class Solution {public: int majorityElement(vector<int>& nums) { unordered_map<int, int> counts; int n = nums.size(); for (int i = 0; i < n; i++) if (++counts[nums[i]] > n / 2) return nums[i]; }};
阅读全文
0 0
- 169. Majority Element (9月8日)
- 169. Majority Element (C++)
- 169. Majority Element (数组)
- 169.Majority Element && 229. Majority Element II
- Leetcode:169. Majority Element(JAVA)
- LeetCode 169. Majority Element(众数)
- LeetCode 169. Majority Element 题解(C++)
- 169. Majority Element (寻找多数元素)
- LeetCode 169. Majority Element(Java)
- LeetCode 169. Majority Element(Python)
- 169. Majority Element (divide and conquer)
- [LeetCode]169.Majority Element
- LeetCode 169.Majority Element
- 【LeetCode】169.Majority Element
- LeetCode 169. Majority Element
- LeetCode 169. Majority Element
- 169.Majority Element
- [leetcode] 169.Majority Element
- 中文乱码,试一试Base64
- socket API接口(2)- socket_create
- Python正则表达式
- 转载:JNI中的jclass和jobject
- mongoDB日期解决
- 169. Majority Element (9月8日)
- Java精华知识点汇总(Most Common Problems in Interview for Java Engineer)
- mysql,5.7:ERROR 1698 (28000): Access denied for user 'root'@'localhost'
- 安卓系统下生成QR码(四)——强制设置掩膜
- HandlerThread实现数字时钟
- 最大报销额
- 数据库引擎介绍
- Java类的初始化顺序
- 网络编程之UDP协议和TCP协议