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

最长无重复子数组

http://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4

import java.util.*;

public class Solution { /** * * @param arr int整型一维数组 the array * @return int整型 */ public int maxLength (int[] arr) { // write code here int len = arr.length; int left = 0; int right = 0; int max = 0; Set set = new HashSet<>(); while(right < len){ if(!set.contains(arr[right])){ set.add(arr[right]); max = max > right - left +1 ? max :right - left +1; right++; continue; } // max = max > right - left +1 ? max :right - left +1; while(set.contains(arr[right])){ set.remove(arr[left]); left ++; } set.add(arr[right]); right ++; } return max; } }

我居南半坡 文章被收录于专栏

多刷题,积蓄力量,欢迎讨论

全部评论

相关推荐

牛至超人:把哈工大,再加大加粗,看见闪闪发光的哈工大字样,面试官直接流口水
投递字节跳动等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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