一、题目内容
二、题解
解法1:
思路
双指针,标记左右游动窗口
set当做队列使用,发现右侧新入栈重复,则remove
代码
public class Solution {public int maxLength(int[] arr) {// write code hereSet<Integer> set = new HashSet<>();int max = 0;int left = 0, right = 0;while (right < arr.length) {while (set.contains(arr[right])) {set.remove(arr[left++]);}set.add(arr[right++]);max = Math.max(max, right - left);}return max;}}
