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 ...
随机推荐
- ubuntu 16.04 安装brackets
1 github 上下载deb包 2 双击deb包但是安装不了(无任何提示,是因为缺少lib文件) 网上给出的解决方案 使用debtool 接压 deb包 把缺少的lib复制进去 配置文件中去掉该 l ...
- copy GC 和 mark & compaction GC的算法异同
先标记 然后 copy GC是,对所有child,判断, 如果child没有被访问过,那么拷贝到新地址,child的forwording指向新地址,child标记为已访问,把自己对child的引用改为 ...
- php查询快递的类
<?php/** * Express.class.php 快递查询类 * * @copyright widuu * @license ...
- lettuce行为驱动框架实例
练习: 一:e1_MyFirstBDD 使用方法的方式实现阶乘的计算 zero.feature: Feature: Compute factorial In order to play with Le ...
- QT | 记录自己遇到的报错
QT 常见报错,及相应对策 0. 遇到所有莫名其妙的问题(完全按照教程,但一直报错) 删除工程文件同级目录下的构建文件(以build开头的文件夹) 重新执行qmake 重新构建项目 检查所有的路径问题 ...
- C++调用ffmpeg.exe提取视频帧
有时候,我们获得一段视频,需要将其中的每一帧都提取出来,来进行一些相关的处理,这时候我们就可以需要用到ffmpeg.exe来进行视频帧的提取. ffmpeg简介:FFmpeg是一套可以用来记录.转换数 ...
- Linux搭建bugfree
1.xampp安装包地址: 链接:https://pan.baidu.com/s/1Th2QvF77jvIGzMROoF2rbg 密码:yoar 2.因为我用的是xshell5连接Linux服务器,直 ...
- Nmap版本检测
-sV (版本检测) 打开版本检测.同时可以使用-A打开系统探测和版本探测. --allports(不为版本探测排除任何端口) 默认情况下,Nmap版本探测会跳过9100 TCP端口,也可以不理会任何 ...
- string函数的一些实现
/************************************************************************* > File Name: test.cpp ...
- 缓存与数据库一致性之三:缓存穿透、缓存雪崩、key重建方案
一.缓存穿透预防及优化 缓存穿透是指查询一个根本不存在的数据,缓存层和存储层都不会命中,但是出于容错的考虑,如果从存储层查不到数据则不写入缓存层,如图 11-3 所示整个过程分为如下 3 步: 缓存层 ...