728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.HashMap;
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= 10; tc++) {
t = sc.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < 1000; i++) {
int num = sc.nextInt();
map.put(num, map.getOrDefault(num, 0) + 1);
}
int max = Integer.MIN_VALUE;
for (int i = 0; i <= 100; i++) {
max = Math.max(max, map.get(i));
}
int ans = -1;
for (int i = 0; i <= 100; i++) {
if (map.get(i) == max) {
ans = Math.max(ans, i);
}
}
System.out.println("#"+tc+" "+ans);
}
}
}
HashMap에 넣어서 get으로 최댓값을 갱신했다.
728x90