AcWing 799. 最长连续不重复子序列
原题链接
简单
作者:
恒心
,
2021-01-25 10:46:17
,
所有人可见
,
阅读 280
import java.util.*;
import java.io.*;
class Main{
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] num = new int[n];
for(int i = 0; i < n; ++i){
num[i] = sc.nextInt();
}
int res = 0;
int[] s = new int[100010];
for(int i = 0, j = 0; i < n; ++i){
s[num[i]]++;
while(j < i && s[num[i]] > 1){s[num[j++]]--;};
res = Math.max(res, i - j + 1);
}
System.out.println(res);
}
}