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. AndroidStudio连不上Android设备真机

    AndroidStudio连不上Android设备真机 刚好遇到这个问题,查阅了很多资料,看到有人分享了引起该问题的几个原因,我总结了一下: 1.手机设置问题.开USB调试 方法:手机设置-开发人员调 ...

  2. SharePoint REST API - 使用REST接口对列表设置自定义权限

    博客地址:http://blog.csdn.net/FoxDave SharePoint网站.列表和列表项都属于SecurableObject类型.默认情况下,一个安全对象继承父级的权限.对一个对 ...

  3. eclipse中创建DataBase Connections

    1.window --> show view --> other --> Data Management --> Data Exploerer --> ok: 2.右键单 ...

  4. kafka consumer重复消费问题

    在做分布式编译的时候,每一个worker都有一个consumer,适用的kafka+zookeep的配置都是默认的配置,在消息比较少的情况下,每一个consumer都能均匀得到互不相同的消息,但是当消 ...

  5. Shell脚本的学习笔记一:变量

    三种变量: 局部变量:局部变量在脚本或命令中定义,仅在当前shell实例中有效,其他shell启动的程序不能访问局部变量. 环境变量:所有的程序,包括shell启动的程序,都能访问环境变量,有些程序需 ...

  6. Nginx 单个进程允许的最大连接数

    (1) 控制 Nginx 单个进程允许的最大连接数的参数为 worker_connections ,这个参数要根据服务器性能和内存使用量来调整 (2) 进程的最大连接数受 Linux 系统进程的最大打 ...

  7. day 08 字符编码和文件的读写操作

    打开文件的语法 f=open("test.txt",encoding=:"utf-8") #给系统发送一个指令,让操作系统去打开文件 使用上面的方法打开文件的方 ...

  8. enctype="multipart/form-data"表单传值问题

    问题: form表单的enctype设置为multipart/form-data后,表单中除了文件后台能拿到,其他值后台都拿不到. 知识点: 一.application/x-www-form-urle ...

  9. C++中多维数组传递参数

    在c++自定义函数时我们有时需要传递参数,有时以多维数组作为参数,这里就遇到了多维数组该怎么传值的问题了,首先我们看看一维数组是怎么做的. void print_num(int num[], int ...

  10. selenium-java,selenium版本和火狐浏览器版本对应关系

    selenium3.5.0,firefox57,geckodriver-v0.19.1