• 문제 링크
https://www.acmicpc.net/problem/5883
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Set<Integer> set = new HashSet<>();
int[] arr = new int[read()];
for (int i = 0; i < arr.length; i++) set.add(arr[i] = read());
int max = 0;
for (int n : set) {
int cnt = 0, i = arr[0];
for (int j : arr) {
if (n == j) continue;
if (i == j) max = Math.max(max, ++cnt);
else {
cnt = 1;
i = j;
}
}
}
bw.write(String.valueOf(max));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 16439 치킨치킨치킨 - Brute Force / Java (0) | 2025.10.20 |
---|---|
[백준] 32401 ANA는 회문이야 - Brute Force / Java (0) | 2025.10.19 |
[백준] 30216 Increasing Sublist - Brute Force / Java (0) | 2025.10.18 |
[백준] 32386 KCPC에 등장할 알고리즘 맞히기 - Data Structure / Java (0) | 2025.10.16 |
[백준] 22233 가희와 키워드 - Data Structure / Java (0) | 2025.10.16 |
댓글