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. Linux:CentOS 7系统的安装

    相信有看过我写的博文就知道我写的第一篇博文就是CentOS 7系统的安装,不过是在虚拟机中安装的,而且还是直接加载镜像文件进去的,不过这次我就通过PE来安装,来证实下PE是否可以用来安装Linux系统 ...

  2. python自学第14天 类

    面向对象:世界万物,皆可分类:世界万物,皆为对象 只要是对象,就肯定属于某种品类. 只要是对象,就肯定有属性 类 对象 封装 继承 多态 一个接口,多种实现

  3. C#程序优化的50种方案

    一.用属性代替可访问的字段 1..NET数据绑定只支持数据绑定,使用属性可以获得数据绑定的好处: 2.在属性的get和set访问器重可使用lock添加多线程的支持. 二.readonly(运行时常量) ...

  4. Idea 2017.3以后版本的破解

    自从升级到idea2017.3之后,之前的license server破解方法貌似已失效.于是找到大神用的破解插件,很好很强大. 安装好idea之后不要打开软件,从http://idea.lanyus ...

  5. css布局与文档流的关系之float(浮动)

    所谓文档流,指元素在排版布局的过程中,元素会自动从左到右,从上到下的流式排列.脱离文档流呢,就是元素打乱了这个排列,或是从排版中拿走. 说到文档流呢,我们先来说一下元素,每个元素呢,都有display ...

  6. objdump和backtrace的配合使用

    在程序调试过程中程序崩溃的情况时有发生,把出问题时的调用栈信息打印出来是一种不错的解决办法. 当然还有一些其他方法:https://www.cnblogs.com/jiangyibo/p/865372 ...

  7. java_lambda表达式

    lambda表达式1    由来    概念        是通过策略模式来曲线实现的    lambda表达式2    语法详解    lambda表达式3    目标类型的概念    目标类型推断 ...

  8. 第2章 Java基本语法(上): 变量与运算符

    2-1 关键字与保留字 关键字(keyword) 保留字(reserved word) 2-2 标识符(Identifier) 案例 class Test{ public static void ma ...

  9. Illegalmixofcollations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT)foroperation '= 连表查询排序规则问题

    两张 表 关联 ,如果 join的字段 排序规则 不一样就会出这个问题 . 解决办法 ,统一 排序规则. 在说说区别,utf8mb4_general_ci 更加快,但是在遇到某些特殊语言或者字符集,排 ...

  10. 服务容错和Hystrix

    一.雪崩效应 在微服务架构中,通常有多个服务层调用,如果某个服务不可用,造成调用的服务也不可用,造成整个系统不可用的情况,叫做雪崩效应 二.Hystrix 放雪崩利器Hystrix,基于Netflix ...