查找数组中出现次数超过一半的数字
来源:互联网 发布:华为网络基础知识 编辑:程序博客网 时间:2024/05/02 01:45
package test;public class Test3 {static int solve(int[] arr,int len){int index = -1;int mid = (len)/2;int low = 0;int high = len-1;while(index != mid){index = partition(arr, low, high);if(index == mid) break;if(index>mid){high = index-1;}else{low = index+1;}}return arr[mid];}static int partition(int[] arr,int low,int high){int flag = arr[low];while(low<high){while(low<high && arr[high]>=flag) high--;arr[low] = arr[high];while(low<high && arr[low] <= flag) low++;arr[high] = arr[low];}arr[low] = flag;return low;}public static void main(String[] args) {int[] arr = new int[]{1,2,3,2,2,2,5,4,2};System.out.println(solve(arr, arr.length));}}
0 0
- 查找数组中出现次数超过一半的数字
- 数组中超过出现次数超过一半的数字
- 74.数组中超过出现次数超过一半的数字
- 74 数组中超过出现次数超过一半的数字
- 查找数组中超过出现次数超过一半的数字(找发帖水王)
- 查找数组中某个出现次数超过数组长度一半的数字
- 查找数组中出现次数超过数组长度一半的数字
- 【数组4】数组中出现次数超过一半的数字
- 数组4:数组中出现次数超过一半的数字
- 查找数组中出现次数超过一半的元素
- 数组中出现次数超过一半的数字
- 找出数组中出现次数超过长度一半的数字
- 2-数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字[算法]
- 数组中出现次数超过一半的数字
- 找出数组中出现次数超过一半的数字--百度
- 数组中出现次数超过一半的数字
- 名字就是一切:我的一点经历和经验,公司名、域名、网名、姓名
- Unity5新的AssetBundle系统使用心得
- Bootstrap Carousel(轮播插件)
- 2015-03-11--数据结构开始
- hdu 1002 A + B Problem II
- 查找数组中出现次数超过一半的数字
- Largest number,leetcode
- 内存映射文件原理
- Shell中的&&、 ||、 ()和 {}
- 额无法收到温热通过是大法官
- c++11中lambda
- Android中SQLite应用详解
- 围观围观
- iOS笔记之_OC面向对象语法1