思路:滑动窗口。
用两个指针记录滑动窗口的大小,用一个集合判断是否重复。如果没有重复就扩大窗口;有重复就记录此时最大长度,然后缩小窗口直到没有重复。重复以上过程。
代码:集合实现
import java.util.*;
public class Solution {
/**
*
* @param arr int整型一维数组 the array
* @return int整型
*/
public int maxLength (int[] arr) {
// write code here
Set<Integer> set = new HashSet<>();
int i = 0, j = 0;
int