数组中出现次数超过一般的数字
来源:互联网 发布:it行业 云计算 编辑:程序博客网 时间:2024/05/01 16:54
package 把数组排成最小的数;public class Solution { public int MoreThanHalfNum_Solution(int[] array) { if (null == array) { return 0; } int len = array.length; if (len == 0) { return 0; } int count = 0; int record = array[0]; for (int i = 0; i < len;) { count++; if (i + 1 < len) { if (array[i] != array[i + 1]) { count--; i += 2; if (count == 0) { if (i < len) { record = array[i]; } } } else { count++; i += 2; } } else { break; } } int index = 0; if (count >= 1) { for (int i = 0; i < len; i++) { if (record == array[i]) { index++; } } if (index >= len / 2 + 1) { return record; } else { return 0; } } else { return 0; } } public static void main(String[] args) { int[] array = { 1, 2, 3, 2, 4, 2, 5, 2, 3 }; System.out.println(new Solution().MoreThanHalfNum_Solution(array)); }}
0 0
- 数组中出现次数超过一般的数字
- 面试题29:数组中出现次数超过一般的数字
- 数组中超过出现次数超过一半的数字
- 74.数组中超过出现次数超过一半的数字
- 74 数组中超过出现次数超过一半的数字
- 【数组4】数组中出现次数超过一半的数字
- 数组4:数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字
- 找出数组中出现次数超过长度一半的数字
- 2-数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字[算法]
- 数组中出现次数超过一半的数字
- 找出数组中出现次数超过一半的数字--百度
- 数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字
- 数组中出现次数超过一半的数字
- 寻找数组中出现次数超过一半的数字
- ios项目打包
- shader Cg 基本数据类型
- Mysql中的load语句对null的处理
- HYSBZ 2588Spoj 10628. Count on a tree
- numa distance 2
- 数组中出现次数超过一般的数字
- 《C++ Primer Plus(第六版)》(5)(第四章 复合类型 答案2)
- 连续输入密码错误3次,第二天才能登录
- 机器学习-svm.点滴积累
- mysql合并两个表
- linux下安装Mysql
- atitit 短信验证码的源码实现 .docx
- Android Force close是什么引起的?
- 连续型切片与离散加减的思路学习