Skip to content

Commit 2a9b470

Browse files
committed
[level 1] Title: 모의고사, Time: 19.58 ms, Memory: 93.9 MB -BaekjoonHub
1 parent edd4f15 commit 2a9b470

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

프로그래머스/1/42840. 모의고사/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 83.5 MB, 시간: 0.98 ms
7+
메모리: 93.9 MB, 시간: 19.58 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 01월 07일 17:15:26
19+
2025년 09월 03일 20:29:16
2020

2121
### 문제 설명
2222

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
import java.util.*;
22
class Solution {
3-
public int[] solution(int[] answers) {
4-
int[] score=new int[3];
5-
6-
int[] pattern1={1,2,3,4,5};
7-
int l1=pattern1.length;
8-
int[] pattern2={2,1,2,3,2,4,2,5};
9-
int l2=pattern2.length;
10-
int[] pattern3={3,3,1,1,2,2,4,4,5,5};
11-
int l3=pattern3.length;
12-
13-
// 6 -> 1, 4, 2
14-
for(int i=0;i< answers.length;i++){
15-
if(answers[i] == pattern1[i%l1] ){
16-
score[0]++;
3+
public int[] solution(int[] answers) {
4+
int[] person1 = {1,2,3,4,5}; // 5
5+
int[] person2 = { 2, 1, 2, 3, 2, 4, 2, 5}; // 8
6+
int[] person3 = { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; // 10
7+
8+
int totalCnt = answers.length;
9+
int cnt = 0;
10+
int score1 =0;
11+
int score2 =0;
12+
int score3 =0;
13+
while(cnt < totalCnt) {
14+
int ans = answers[cnt];
15+
if(ans == person1[cnt%5]){
16+
score1 ++;
1717
}
18-
if(answers[i] == pattern2[i%l2] ){
19-
score[1]++;
18+
if(ans == person2[cnt%8]){
19+
score2 ++;
2020
}
21-
if(answers[i] == pattern3[i%l3] ){
22-
score[2]++;
21+
if(ans == person3[cnt%10]){
22+
score3 ++;
2323
}
24+
cnt ++;
2425
}
25-
List<Integer> answer=new ArrayList<>();
26-
int maxx=(int)Math.max(score[0],Math.max(score[1],score[2]));
27-
28-
if(maxx==score[0]){
26+
27+
ArrayList<Integer> answer = new ArrayList<>();
28+
int max = (int) Math.max(Math.max(score1,score2),score3);
29+
if(max == score1){
2930
answer.add(1);
3031
}
31-
if (maxx==score[1]) {
32+
if(max == score2){
3233
answer.add(2);
3334
}
34-
if (maxx==score[2]) {
35+
if(max == score3){
3536
answer.add(3);
36-
}
37-
38-
int[] answer2=new int[answer.size()];
39-
for(int i=0;i< answer.size();i++){
40-
answer2[i]=answer.get(i);
41-
}
42-
43-
44-
return answer2;
37+
}
38+
39+
return answer.stream().mapToInt(Integer::intValue).toArray();
4540
}
4641
}

0 commit comments

Comments
 (0)