面试题29:找到数组中出现次数超过一半的数字(java)
来源:互联网 发布:网络黑白txt下载 编辑:程序博客网 时间:2024/05/19 20:59
package _29_findOverHalf;/** * 找到数组中出现次数超过一半的数字 * @author yanjie * */public class FindOverHalf {static int[] data = {1,2,3,2,2,2,5,4,2};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]);}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+" ");}}}
0 0
- 面试题29:找到数组中出现次数超过一半的数字(java)
- 剑指offer-面试题29 找到数组中出现次数超过一半的数字-1
- 面试题:数组中出现次数超过一半的数字
- 面试题:数组中出现次数超过一半的数字
- 剑指Offer面试题29(java版):数组中出现次数超过一半的数字
- 剑指Offer面试题29:数组中出现次数超过一半的数字 Java实现
- 剑指Offer面试题29(java版):数组中出现次数超过一半的数字
- 面试题29:数组中出现次数超过一半的数字
- [剑指offer][面试题29]数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字(面试题 29)
- 剑指Offer:面试题29 数组中出现次数超过一半的数字
- 面试题29 数组中出现次数超过一半的数字
- 剑指offer 面试题29—数组中出现次数超过一半的数字
- 《剑指Offer》学习笔记--面试题29:数组中出现次数超过一半的数字
- 面试题29:数组中出现次数超过一半的数字
- 面试题29:数组中出现次数超过一半的数字
- 【剑指Offer学习】【面试题29 :数组中出现次数超过一半的数字】
- 面试题29_数组中出现次数超过一半的数字
- Weex项目初始化weex-iOS集成
- Android Studio NDK 入门教程(3)--Java与C++之间的类型签名
- 使用CooCox的CoIDE打开mbed项目失败:提示 The chip:STM32F103RB information of current project has sonething wrong
- 猎豹浏览器访问webapp报HTTP405错误
- MapReduce 杂记
- 面试题29:找到数组中出现次数超过一半的数字(java)
- 【数据结构】堆、堆排序笔记
- Java基础之(三十五)输入输出<一>
- JAVA 网络编程(6) Netty TCP 示例
- Qt中QLabel的字符串连接
- js判断浏览器 微信
- jdbc连接oracle数据库
- C compiler cannot create executables checking whether the C compiler works... no
- 接入了微信分享,在分享页面点击返回应用,无法返回到自己的app