Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 |
| 31 |
Tags
- 문제풀이
- priorityqueue
- COS PRO
- 문제해결
- 투포인터
- oracle
- BOJ
- binary search
- Java
- BFS
- 프로그래머스
- SQL
- 알고리즘
- db
- DP
- 코테
- math
- 코딩테스트
- 이분탐색
- greedy
- 백준
- MySQL
- 건강
- SWEA
- 문자열
- 시뮬레이션
- dfs
- 운동기록
- 러닝일지
- 자바
Archives
- Today
- Total
슈콩
COS PRO 1급 JAVA 누가 당선 되나요 본문



[소스 코드]
class Main {
public int[] solution(int N, int[] votes) {
[[(guide-anchor):(한줄을 수정하시오)]]
int voteCounter[] = new int[11];
for (int i = 0; i < votes.length; i++) {
voteCounter[votes[i]] += 1;
}
int maxVal = 0;
int cnt = 0;
for (int i = 1; i <= N; i++) {
if (maxVal < voteCounter[i]) {
maxVal = voteCounter[i];
cnt = 1;
}
else if(maxVal == voteCounter[i]){
cnt += 1;
}
}
int answer[] = new int[cnt];
for (int i = 1, idx = 0; i <= N; i++){
if (voteCounter[i] == maxVal) {
answer[idx] = votes[i];
idx += 1;
}
}
return answer;
}
}