leetcode169
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的更多相关文章
- 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 ...
- Boyer-Moore 算法 Leetcode169
Boyer-Moore 算法 Leetcode169 一.题目 169. 多数元素 给定一个大小为 n 的数组,找到其中的多数元素.多数元素是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素. 你可以假 ...
- 每天一道LeetCode--169.Majority Elemen
Given an array of size n, find the majority element. The majority element is the element that appear ...
- leetcode169——Majority Element (C++)
Given an array of size n, find the majority element. The majority element is the element that appear ...
- [LeetCode169]Majority Element求一个数组中出现次数大于n/2的数
题目: Given an array of size n, find the majority element. The majority element is the element that ap ...
- LeetCode169:Majority Element(Hash表\位操作未懂)
题目来源: Given an array of size n, find the majority element. The majority element is the element that ...
- [Swift]LeetCode169. 求众数 | Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- LeetCode169 求众数
题目链接:https://leetcode-cn.com/problems/majority-element/ 给定一个大小为 n 的数组,找到其中的众数.众数是指在数组中出现次数大于 ⌊ n/2 ⌋ ...
- [LeetCode169]Majority Element
Majority Element Total Accepted: 58500 Total Submissions: 163658My Submissions Question Solution Gi ...
随机推荐
- java中的线程问题(二)——线程的创建和用法。
在java中一个类要当作线程来使用有两种方法. 1.继承Thread类,并重写run函数 2.实现Runnable接口,并重写run函数 因为java是单继承的,在某些情况下一个类可能已经继承了某个父 ...
- webdriver +浏览器驱动
webdriver 经常使用的驱动有ChromeDriver , Firefox 驱动和IE驱动. 在使用的时候需要将对应的驱动下载到本地放到Python的安装路径下,然后添加路径到系统环境变量. 有 ...
- 前端开发【第一篇: HTML】
HTML初识 1.什么是HTML? HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记). 2.网页的组成 我们平时 ...
- pandas 将excel一列拆分成多列重新保存
利用pd.read_excel 做到将第二列“EVT-LBL”按“-”分割后重新加三列在df后面 1 读取表格df 2. 分割第二列短横连接的数字,保存到df2---- 参考:str.spilt( ...
- Ubuntu Server 16.04设置WiFi
wifi :http://www.cnblogs.com/joeyupdo/p/3350463.html http://blog.csdn.net/meic51/article/details/173 ...
- 实验 2:备份和还原IOS
SW1配置 Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch ...
- Atom选中多行操作
没有用过sublime,但是有选取多行的需求 我有一个文本文件,前面几行都是文件夹路径,并且都是单个字母,我想删除路径,保存纯粹的子文件夹名称,这样可以上传谷歌翻译文档,写程序再写txt略显麻烦,直接 ...
- tree-lstm初探
https://zhuanlan.zhihu.com/p/35252733 可以先看看上面知乎文章里面的例子 Socher 等人于2012和2013年分别提出了两种区分词或短语类型的模型,即SU-RN ...
- windows server 修改远程桌面连接端口号
1. [运行]输入 regedit 2. 在注册表编辑器中找到以下PortNamber键,改为要使用的远程端口,如10000. HKEY_LOCAL_MACHINE\SYSTEM\CurrentCo ...
- 回顾ThreadLocal
ThreadLocal作为解决特定场景下并发的一种方案,在Spring等框架及面试中经常会被问到,它是Java必须要掌握的基础知识之一. ThreadLocal类的作用是抽象线程内变量的抽象,这类对象 ...