题解 | #最长无重复子数组#

最长无重复子数组

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
};
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务