博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Majority Element
阅读量:4608 次
发布时间:2019-06-09

本文共 825 字,大约阅读时间需要 2 分钟。

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.

Credits:

Special thanks to for adding this problem and creating all test cases.

1 import java.util.Hashtable; 2  3  4 public class Solution  5 { 6  7     public static int majorityElement(int[] num) 8     { 9         Hashtable
ht=new Hashtable();10 for(int i=0;i
=num.length/2)17 return num[i]; 18 }19 return 0;20 }21 22 public static void main(String args[])23 {24 int[] num={6,5,5};25 System.out.println(majorityElement(num));26 }27 }

 

转载于:https://www.cnblogs.com/qq1029579233/p/4403502.html

你可能感兴趣的文章
What are Upgrade, Product and Package Codes used for? By pusu
查看>>
【转】梯度下降算法以及其Python实现
查看>>
H5的本地存储
查看>>
1035 Password (20 分)
查看>>
VC静态连接库注意事项
查看>>
并不对劲的hdu4777
查看>>
如何在个人博客首页中添加访问计数器
查看>>
Morning Reading Collection
查看>>
Sudo
查看>>
JS案例之8——从一个数组中随机取数
查看>>
C#中Dictionary小记
查看>>
mysql日期类型默认值'0000-00-00'容错处理
查看>>
openni和骨架追踪 rviz查看---34
查看>>
防止网站被iframe调用
查看>>
B - 畅通工程(并查集)
查看>>
linux使用rz、sz快速上传、下载文件
查看>>
基础练习 Huffuman树
查看>>
判断数字的正则表达式
查看>>
DOC常用命令(转)
查看>>
php写一个判断是否有cookie的脚本
查看>>