-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path16472.java
More file actions
29 lines (23 loc) · 972 Bytes
/
16472.java
File metadata and controls
29 lines (23 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.*;
public class Main {
static int[] arr = new int[26]; // 각 알파벳 문자의 개수 저장 (a~z)
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
String string = br.readLine();
int cnt = 0; // 윈도우 안에서 서로 다른 문자 종류의 수
int a = 0; // 조건을 만족하는 가장 긴 부분 문자열의 길이
int start = 0;
int end = 0;
for(start = 0, end = 0; end < string.length(); end++) { // 슬라이딩 윈도우
if(arr[string.charAt(end) - 'a']++ == 0) {
cnt++;
}
while (N < cnt && start < end) {
if (--arr[string.charAt(start++) - 'a'] == 0) cnt--;
}
a = Math.max(a, end - start + 1);
}
System.out.println(a);
}
}