最长连续不重复子序列_java


import java.util.*;

public class Main{
    private static int N=100010;
    private static int[] res=new int[N];
    private static int[] temp=new int[N];
    
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        for(int i=0;i){
            res[i]=in.nextInt();
        }
        int x=0;
        for(int i=0, j=0; i){
            temp[res[i]]++;
            while(temp[res[i]]>1){
                temp[res[j]]--;
                j++;
            }
            x=Math.max(x,i-j+1);
        }
        System.out.print(x);
    }
}