#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. 解决MyEclipse吃内存以及卡死的方法

    前言:MyEclipse5.5 大小 139M:MyEclipse6.5 大小 451M:MyEclipse7.0 大小 649M!下载服务器又是国外的...下载速度累人也就罢了,只要你工作性能一流. ...

  2. Linux环境命令大全

    java环境比较常用的几个命令: cd /  切换目录, cd ../切换到上级目录 rm -rf 文件名 删除文件 jar -xvf 文件名  解压文件 mv 文件 新路径  将当前路径下面的文件移 ...

  3. 8月11日 Power-BI V11 QQ群视频交流开课啦

    过去,用excel表格来做数据分析是很多企业的首选,但随着时代的发展,excel的某些功能已经不能满足用户的需求.今天的课程呢,我们就基于excel数据源来讲讲数据集构建器的应用. 时间:2016年8 ...

  4. VisualStudio如何以源码文本方式打开rc文件

    视图 >> 解决方案资源管理器 >> 右击XXX.rc >> 打开方式 >> 源代码(文本)编辑器

  5. 线程池——JAVA并发编程指南

    TPS00-J. 用线程池实现应用在流量暴涨时优雅降级 很多程序都要解决这样一个问题——处理一系列外来的请求.Thread- Per-Message这种设计模式是最简单的并发策略了,它为每一个请求创建 ...

  6. SWING

    第一个图形界面应用程序.图形用户界面简称GUI(Graphical User Interface),通过GUI用户可以更好地与计算机进行交互.Swing简介Swing工具包提供了一系列丰富的GUI 组 ...

  7. 为Virtual Studio Code配置Python调试插件(Ubuntu14.04)

    详情见以下python for virtual studio code插件的链接: python 安装依赖 1.Python is installed on the current system Pa ...

  8. span和div的区别

    <span> 在CSS定义中属于一个行内元素,在行内定义一个区域,也就是一行内可以被 <span> 划分成好几个区域,从而实现某种特定效果. <span> 本身没有 ...

  9. CollectionView添加头尾部

    //上下拉头尾部 self.collectionView.footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self ref ...

  10. Swift游戏实战-跑酷熊猫 02 创建熊猫类

    要点: 如何继承SKSpriteNode :子类必须调用SKSpriteNode的一个指定构造器 init(){ super.init(texture:texture,color:UIColor.wh ...