题解 | #最长的可整合子数组的长度#
最长的可整合子数组的长度
http://www.nowcoder.com/practice/677a21987e5d46f1a62cded9509a94f2
let num = parseInt(readline()); let str = readline().split(" ").map(Number); let arr = [], s = 0, count = 0; str.sort((a, b) => a - b);
for (let i = 0; i < num - 1; i++) { if (str[i + 1] - str[i] > 1) { let tem = i + 1 - s-count; arr.push(tem === 2||tem === 3 ? 1 : tem); s = i+1; } else if (str[i + 1] === str[i]) { count++; } else if (i + 1 === num - 1) { let tem = i + 2 - s-count; arr.push(tem === 2||tem === 3 ? 1 : tem); } } arr.sort((a, b) => b - a); print(arr[0]);