mostFrequentSubArray
来源:互联网 发布:php面试自我介绍 编辑:程序博客网 时间:2024/06/08 11:15
Given an array of ints, find the most frequent non-empty subarray in it. If there are more than one such sub-arrays return the longest one/s.
Note: Two subarrays are equal if they contain identical elements and elements are in the same order.
For example: if input = {4,5,6,8,3,1,4,5,6,3,1}Result: {4,5,6}private static void longestSubseq(int a[]) { int len = 1; int maxLen = 1; int index = 0; for (int i = 0; i < a.length-1; ++i) { if (a[i+1] == a[i] + 1) { len++; if (len > maxLen) { maxLen = len; index = i+1; } } else { len = 1; } } System.out.println(maxLen); for (int i = index - maxLen+1; i <= index; ++i) System.out.print(a[i] + " "); } int input[] = {4,5,6,8,3,1,4,5,6,3,1}; int aaa[] = {1,2,3,4,4,1,3,2,1,2}; int[] array = new int[] { 1, 2, 3, 4, 5, 6, 2, 3, 4, 5, 9, 7, 8, 9, 1, 2, 7, 8, 9, 1, 2 }; int xa[] = {3}; longestSubseq(xa);
- mostFrequentSubArray
- ASIDownloadCache 设置下载缓存 以及其他
- Redis配置文件解读
- Android下 使用百度地图sdk
- linux路由内核实现分析(三)---路由查找过程
- 路庆晖:有效提升电商用户访问体验_亿邦电商两会
- mostFrequentSubArray
- Seven habits of effective text editing using Vim
- 程序崩溃时打印调用栈
- 黑马程序员—Java提高2(泛型,内省)
- 10个你必须掌握的超酷VI命令技巧
- Cauchy-Schwarz不等式的证明
- 初识block
- 实现几个字符串常用函数
- MySQL学习足迹记录07--数据过滤--用正则表达式进行检索