给定无序数组arr,返回其中最长的连续序列的长度(要求值连续,位置可以不连续,例如 3,4,5,6为连续的自然数)
数据范围:
,数组中的值满足 
要求:空间复杂度
,时间复杂度
function MLS( arr ) {
// write code here
const newArr = [...new Set(arr)].sort((a, b) => a - b)
let max = 0
let point = -1
let pre = Infinity
newArr.forEach((item, index) => {
if (point === -1) {
max = 1
point = 0
} else {
if (item === pre + 1) {
max = Math.max(max, index - point + 1)
} else {
point = index
}
}
pre = item
})
return max
}