Skip to content

Commit 99f48c6

Browse files
authored
[20250705] BOJ / G4 / 고냥이 / 김수연
1 parent 175a7a7 commit 99f48c6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
```java
2+
import java.io.*;
3+
4+
public class boj16472 {
5+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+
7+
public static void main(String[] args) throws Exception {
8+
int N = Integer.parseInt(br.readLine());
9+
String input = br.readLine();
10+
int[] alpha = new int[26];
11+
int cnt = 0, answer = 0, start = 0, end = -1;
12+
13+
while (++end < input.length()) {
14+
if (alpha[input.charAt(end) - 'a']++ == 0) cnt++;
15+
16+
while (N < cnt) {
17+
if (--alpha[input.charAt(start++) - 'a'] == 0) cnt--;
18+
}
19+
20+
answer = Math.max(answer, end - start + 1);
21+
}
22+
System.out.println(answer);
23+
}
24+
}
25+
```

0 commit comments

Comments
 (0)