题解 | #最长无重复子数组#
最长无重复子数组
http://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4
*
* @param arr int整型一维数组 the array
* @return int整型
*/
function maxLength( arr ) {
// write code here
let temp = [];
let max = 0;
for(let item of arr) {
let index = temp.indexOf(item);
if(index !== -1) {
temp = temp.slice(index+1);
}
temp.push(item);
max = Math.max(max,temp.length);
}
return max;
}
module.exports = {
maxLength : maxLength
};