由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求Longest_Increasing_Subsequence JAVA O(nlgn) 代码
相关主题
g公司面试问Longest increasing subsequence,意义在哪里?这个怎么弄?
longest increase subsequenceLongest Increasing Subsequence O(NLOG(N)) 解法
Maximum Sum of Increasing Sequence看到一个longest increasing subsequence挺有意思的算法
Facebook interview 面经Longest Increasing Subsequence用binary还能输出结果数组吗?
问个算法题5帮忙看个题
nlogn for longest increasing subsequencefind all longest increasing subsequence 谁有源码?
最长递增子array的算法Longest Increasing Subsequence要掌握nlogn的解法吗?
longest increasing subsequence O(NlogN)算法中数组 P 是否必Random Array number, Find longest consecutive sequence
相关话题的讨论汇总
话题: int话题: mid话题: array话题: maxnow
进入JobHunting版参与讨论
1 (共1页)
m*****k
发帖数: 731
m********g
发帖数: 272
2
public static int longestIncreasingSubConsequence(int[] array) {
int length = array.length;
int[] valueAtLength = new int[length];
int maxNow = 1;
valueAtLength[0] = array[0];
for(int i = 1; i < length; i++) {
int updatePos = findPos(valueAtLength, maxNow, array[i]);
if(updatePos == maxNow) {
valueAtLength[maxNow++] = array[i];
} else {
valueAtLength[updatePos] = array[i];
}
}
return maxNow;
}
private static int findPos(int[] array, int length, int target) {
int low = 0;
int high = length - 1;
while(low <= high) {
int mid = (low + high) / 2;
if(mid == low) {
if(array[mid] >= target) {
return mid;
} else {
mid = mid + 1;
if(mid > high) {
break;
}
}
}
if(array[mid] >= target && array[mid - 1] < target) {
return mid;
} else if (array[mid] < target) {
low = mid + 1;
} else if(array[mid - 1] >= target) {
high = mid - 1;
}
}
return length;
}
变量的naming不好,自己可以修改
m*****k
发帖数: 731
3
谢谢myanything 大虾,
int[] array= new int[] { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7,
15
};
如何输出 0 2 6 9 11 15 呢?
m********g
发帖数: 272
4
每次cached的时候把整个序列都cache下来,最后print out那个最长的序列
m*****k
发帖数: 731
5
刚在collabedit上被问到这道题,干脆就直接拷贝了,面试官,一国人兄弟说他看到过
这段code,
既然这样,我也不需隐瞒,直接告诉他就是我发帖要的code,再装没见过就太掩耳
盗铃了,呵呵。
看来国人兄弟也是有意放水,谢过了哈!
1 (共1页)
进入JobHunting版参与讨论
相关主题
Random Array number, Find longest consecutive sequence问个算法题5
面试题count # of increasing subsequences of String求解nlogn for longest increasing subsequence
热腾腾的twitter电面经最长递增子array的算法
leetcode上的大oj和小oj有什么本质差别吗?longest increasing subsequence O(NlogN)算法中数组 P 是否必
g公司面试问Longest increasing subsequence,意义在哪里?这个怎么弄?
longest increase subsequenceLongest Increasing Subsequence O(NLOG(N)) 解法
Maximum Sum of Increasing Sequence看到一个longest increasing subsequence挺有意思的算法
Facebook interview 面经Longest Increasing Subsequence用binary还能输出结果数组吗?
相关话题的讨论汇总
话题: int话题: mid话题: array话题: maxnow