#include<map>

using namespace std;
class Solution {
public:
    int majorityElement(vector<int>& nums) {
       map<int,int> m;
       int n=nums.size();
       int i=0;
       while(i<nums.size()){
    if(m.count(nums[i]))   m[nums[i]]++;
    else m.insert(pair<int,int>(nums[i],1));
    i++;
    }
       i=0;
       map <int, int>::iterator m1_Iter;

for ( m1_Iter = m.begin( ); m1_Iter != m.end( ); m1_Iter++ ){

      if(m1_Iter->second>n/2)
      return m1_Iter->first;

     }

}

};

Majority Element的更多相关文章

  1. [LeetCode] Majority Element II 求众数之二

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...

  2. [LeetCode] Majority Element 求众数

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  3. 【leetcode】Majority Element

    题目概述: Given an array of size n, find the majority element. The majority element is the element that ...

  4. ✡ leetcode 169. Majority Element 求出现次数最多的数 --------- java

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  5. (Array)169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  6. LeetCode 169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  7. [UCSD白板题] Majority Element

    Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...

  8. Leetcode # 169, 229 Majority Element I and II

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  9. LeetCode【169. Majority Element】

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  10. 【10_169】Majority Element

    今天遇到的题都挺难的,不容易有会做的. 下面是代码,等明天看看Discuss里面有没有简单的方法~ Majority Element My Submissions Question Total Acc ...

随机推荐

  1. Android 使用Okhttp/Retrofit持久化cookie的简便方式

    首先cookie是什么就不多说了,还是不知道的话推荐看看这篇文章 Cookie/Session机制详解 深入解析Cookie技术 为什么要持久化cookie也不多说了,你能看到这篇文章代表你有这个需求 ...

  2. 九个uname命令获取Linux系统详情的实例

    当你在控制台模式下,无法通过“鼠标右键 > 关于”获取操作系统的信息.这时,在Linux下,你可以使用uname命令,帮助你完成这些工作. Uname是unix name的缩写.在控制台中实际使 ...

  3. 蒋鑫:为什么 Git 比 SVN 好

    在版本控制系统的选型上,是选择Git还是SVN? 对于开源项目来说这不算问题.使用Git极大地提高了开发效率.扩大了开源项目的参与度. 增强了版本控制系统的安全性,选择Git早已是大势所趋. 但对于企 ...

  4. Power-BI 关于2016年7月份深圳一手房房价分析报表 腾讯课堂开课啦

         上周我们的公开课讲了全国房地产投资开发的情况,通过对时间.区域等多维度的分析,透析了全国房地产开发的投资情况.这周呢,我们就全国一线城市的房价,选取了深圳作为分析对象,对深圳一手房房价进行一 ...

  5. checkbox的完美用户体验(转)

    如需查看效果-->自行建个html文件,或者-->原文:http://bbs.blueidea.com/thread-2711834-1-7.html 最常见的checkbox的使用: & ...

  6. ADO.Net 数据库访问技术

    1.在web.Config配置文件中设置连接字符串 <connectionStrings> <add name="connString" connectionSt ...

  7. "provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接"错误的解决方法

    这个错误主要有以下几个原因造成: 1. 错误的连接字符串:例如数据源的实例名称“\"错误写成"/"了 2.Named Pipes(NP)没有启动 其他原因,详见:http ...

  8. Orchard学习系列-----如何运行的

    感慨:当接触到微软这套程序时,代码实在是太好了,好的几乎都读不懂.很久之前就对这个套开源程序特别感兴趣,但读不明白也让人郁闷. 背景(Orchard官网): 可组装系统的CMS系统,OrChard在运 ...

  9. 类似 select 选择框效果及美化

    网上有各种各样的关于 select 选择框的美化,找了很多,并没有好的样式效果.所以就找了一个利用 ul li 做的类似 select 选择框的效果,不废话了,先上图,效果如下: 对于上图的箭头效果, ...

  10. node.js npm权限问题try running this command again as root/Administrator.

    npm install报错; try running this command again as root/Administrator. 以管理员身份打开cmd 开始菜单->所有程序->附 ...