public class Solution {
public int MajorityElement(int[] nums) {
Dictionary<int, int> dic = new Dictionary<int, int>(); var len = nums.Length; for (int i = ; i < len; i++)
{
if (!dic.ContainsKey(nums[i]))
{
dic.Add(nums[i], );
}
else
{
dic[nums[i]]++;
}
} var result = ; foreach (var d in dic)
{
if (d.Value > len / )
{
result = d.Key;
break;
}
}
return result;
}
}

https://leetcode.com/problems/majority-element/#/description

leetcode169的更多相关文章

  1. LeetCode169 Majority Element, LintCode47 Majority Number II, LeetCode229 Majority Element II, LintCode48 Majority Number III

    LeetCode169. Majority Element Given an array of size n, find the majority element. The majority elem ...

  2. Boyer-Moore 算法 Leetcode169

    Boyer-Moore 算法 Leetcode169 一.题目 169. 多数元素 给定一个大小为 n 的数组,找到其中的多数元素.多数元素是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素. 你可以假 ...

  3. 每天一道LeetCode--169.Majority Elemen

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

  4. leetcode169——Majority Element (C++)

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

  5. [LeetCode169]Majority Element求一个数组中出现次数大于n/2的数

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

  6. LeetCode169:Majority Element(Hash表\位操作未懂)

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

  7. [Swift]LeetCode169. 求众数 | Majority Element

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

  8. LeetCode169 求众数

    题目链接:https://leetcode-cn.com/problems/majority-element/ 给定一个大小为 n 的数组,找到其中的众数.众数是指在数组中出现次数大于 ⌊ n/2 ⌋ ...

  9. [LeetCode169]Majority Element

    Majority Element Total Accepted: 58500 Total Submissions: 163658My Submissions Question Solution  Gi ...

随机推荐

  1. React项目新手指南

    对于程序员而言:驼峰和下划线之间是一场宗派战争:大括号是否换行会成为一种党派:逗号写在行尾还是行首的人来自不同星球…… 然而,无规矩不成方圆,任何一个团队,要想有高质量的产出,第一步必须要对一些基本的 ...

  2. Alpha冲刺5

    前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/9989898.html 作业博客:https://edu.cnblogs.com/campus/ ...

  3. 18-09-20 关于Xlwings读写基础1

    一 利用xlwings 读取Excel 的读取修改数据 import xlwings as xw""" # 1. 读一个已存在的Excel文件:利用xlwings 读取E ...

  4. linux之目录知识

    /var 目录下的路径知识: /var/log    记录系统及软件运行信息文件所在目录 /var/log/messages 系统级别日志文件 /var/log/secure 用户登录信息日志文件 / ...

  5. keil项目的调试与编译

    编译: Translate===编译单个文件 Build====编译当前项目,如果该项目先前编译过1次,并且文件没有编辑改动,则点击时不会重新编译 Rebuild===重新编译,每点击一次就重新编译. ...

  6. 算法笔记1 - 编辑距离及其动态规划算法(Java代码)

    转载请标注原链接:http://www.cnblogs.com/xczyd/p/3808035.html 编辑距离概念描述 编辑距离,又称Levenshtein距离,是指两个字串之间,由一个转成另一个 ...

  7. 面试题 -AR VR MR以及CR的简单介绍

    AR 增强现实技术(Augmented Reality,简称 AR),是一种实时地计算摄影机影像的位置及角度并加上相应图像.视频.3D模型的技术,这种技术的目标是在屏幕上把虚拟世界套在现实世界并进行互 ...

  8. 初识mysql数据库

    mysqld install :找到你的库 net start mysql ;启动mysql的服务端(server) mysql -uroot -p :启动mysql的客户端(Client) exit ...

  9. 添加mtdparts引起的问题

    今天在给uboot添加分区,大家都知道添加完之后直接在终端里面mtd会报错: SMDK2440 # mtd mtdparts variable not set, see 'help mtdparts' ...

  10. QT4.8.6-VS2010开发环境配置

    目录 1.下载软件 2.环境配置 3.VAssistX配置 1.下载软件 VS2010下载地址:链接: https://pan.baidu.com/s/1gvPjZWBtSEwW37H1xf2vbA ...