题解 | #数组中的最长连续子序列#
数组中的最长连续子序列
http://www.nowcoder.com/practice/eac1c953170243338f941959146ac4bf
/**
* max increasing subsequence
* @param arr int整型一维数组 the array
* @return int整型
*/
function MLS( arr ) {
// write code here
//注意去重
if(arr.length === 0){
return 0
}
let ret = 1;
let max = 0;
let tempset = arr.sort(function(a,b){
return a-b;
})
let temp = Array.from(new Set(tempset))
for(let i = 0;i<temp.length;i++){
if(temp[i] == temp[i-1]){
continue
}
if(temp[i]+1 === temp[i+1]){
ret++;
}else{
ret = 1;
}
max = Math.max(ret,max)
}
return max
}
module.exports = {
MLS : MLS
};