Majority Element
来源:互联网 发布:不想找女朋友 知乎 编辑:程序博客网 时间:2024/04/18 06:27
题目来自于:
LeetCode 169.Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋
times.
You may assume that the array is non-empty and the majority element always exist in the array.
language: javascript
/** * @param {number[]} nums * @return {number} */var majorityElement = function(nums) { var count = 0; var number = 0; for(var i=0;i<nums.length;i++){ if(count === 0){ number = nums[i]; count = 1; }else{ if(number == nums[i]){ count++; }else{ count--; } } } return number;};
0 0
- majority element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- Majority Element
- majority element
- Majority Element
- Majority Element
- 道与JAVA(一)
- java中的JTable类
- poj3368
- wamp2.5 配置站点
- node socket搭建简单聊天室
- Majority Element
- Linux 命令解压缩
- 搭建OpenCV 3.1、OpenNi2、Qt 5.5、VS2010开发环境
- Android 消息机制源码分析
- 自定义控制器的转场动画(Push、Pop)
- Unity3D Ios 打包注意事项
- 数组的练习 ----最大最小值
- VirtualBox虚拟机网络环境解析和搭建-NAT、桥接、Host-Only、Internal、端口映射
- Flask环境搭建