找到数组中出现次数超过一半的数字
来源:互联网 发布:js string转timestamp 编辑:程序博客网 时间:2024/05/14 06:46
package test1;/** * 找到数组中出现次数超过一半的数字 * @author yanjie * */public class Test {static int[] data = {1,2,3,2,2,2,5,4,2};public static int partion(int[] data, int low, int high){int temp = data[low];while(low<high){while(low<high && data[high]>=temp)high--;data[low] = data[high];while(low<high && data[low]<=temp)low++;data[high] = data[low];System.out.println(low+" "+high);}data[low] = temp;return low;}public static int bisearch(int[] data, int low, int high, int mid){int par = 0;while(par!=mid){par = partion( data, low, high);if(par==mid){return data[par];}else if(par<mid){low = par+1;}else if(par>mid){high = par-1;}}return 0;}public static void print(int[] data){for(int i: data){System.out.print(i+" ");}}public static void main(String[] args) {// TODO Auto-generated method stubprint(data);int mid = (data.length)/2;int mid_data = bisearch(data, 0, data.length-1, mid);System.out.println(data[mid_data]);}}
0 0
- 找到数组中出现次数超过一半的数字
- 找到数组中出现次数超过一半的数字
- 数组中超过出现次数超过一半的数字
- 74.数组中超过出现次数超过一半的数字
- 74 数组中超过出现次数超过一半的数字
- java 找到数组中出现次数超过数组长度一半的那个数字
- 面试题29:找到数组中出现次数超过一半的数字(java)
- 剑指offer-面试题29 找到数组中出现次数超过一半的数字-1
- 【数组4】数组中出现次数超过一半的数字
- 数组4:数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字
- 找出数组中出现次数超过长度一半的数字
- 2-数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字[算法]
- 数组中出现次数超过一半的数字
- 找出数组中出现次数超过一半的数字--百度
- 数组中出现次数超过一半的数字
- Android进阶UI之BadgeView(数字提醒)
- 读《Android开发艺术探索》后的面试题整理
- 浏览器对js中nextSibling与previousSibling属性的支持
- awk命令详解
- JAVA设计模式初探之桥接模式
- 找到数组中出现次数超过一半的数字
- 49.View the Exhibit to examine the output of the DBA_OUTSTANDING_ALERTS view.
- HDU(4883)TIANKENG’s restaurant(模拟+贪心)
- sed命令详解
- 函数时间复杂度的计算详解(转自CSDN)
- 直播推流端网络优化策略
- php基础语法之函数篇
- ros的技术准备
- CALayer