|
์ฝ๋ ์์ฑํ๊ธฐ
import java.util.*;
class Solution {
//1๋ฒ ์ํฌ์ ๋ฐฉ์ 1 2 3 4 5
//2๋ฒ ์ํฌ์ ๋ฐฉ์ 2 1 2 3 2 4 2 5
//3๋ฒ ์ํฌ์ ๋ฐฉ์ 3 3 1 1 2 2 4 4 5 5
//๊ฐ์ฅ ๋ง์ด ๋งํ ์ฌ๋์ ๋ฆฌํดํ๊ณ , ์ฌ๋ฟ์ผ ๊ฒฝ์ฐ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
public int[] solution(int[] answers) {
List<Integer> list = new ArrayList<>();
int[] student1 = {1,2,3,4,5};
int score1 =0;
int[] student2 = {2,1,2,3,2,4,2,5};
int score2 =0;
int[] student3 = {3,3,1,1,2,2,4,4,5,5};
int score3 =0;
//์ ๋ต ์ฒดํฌ
for(int i=0;i<answers.length;i++){
if(student1[i%student1.length]==answers[i]){
score1++;
}
if(student2[i%student2.length]==answers[i]){
score2++;
}
if(student3[i%student3.length]==answers[i]){
score3++;
}
}
//์ ์ ์ต๋๊ฐ
int max = Math.max(Math.max(score1,score2),score3);
//์๋ ๋ก์ง๋๋ก list๋ฅผ ์ฑ์ฐ๋ฉด, ์ค๋ฆ์ฐจ์ ์ ๋ ฌ์ด ๋๋ค.
if(max == score1){
list.add(1);
}
if(max==score2){
list.add(2);
}
if(max==score3){
list.add(3);
}
//์ฑ์์ง list์ ํฌ๊ธฐ์ ๊ฐ์ ๋ฐฐ์ด์ ์์ฑํ๊ณ , ์ฑ์ด๋ค.
int [] answer = new int[list.size()];
for(int i=0;i<list.size();i++){
answer[i]=list.get(i);
}
return answer;
}
}
Java
๋ณต์ฌ
|
์ฝ๋ ์ค๋ช
ํ๊ธฐ
์์
์๊ฐ์ ํ์๋ ๋ฌธ์ ์๋๋ฐ, ๋ง์ ํ๋ ค๊ณ ํ๋ ๋ฐ๋ก ๊ธฐ์ต๋์ง ์์๋ค..ใ
ใ
๋ค๋ค ๋น์ทํ ๋ฐฉ๋ฒ์ผ๋ก ํผ ๊ฒ ๊ฐ๋ค.
์ค๋ณต๋๋ ์ฝ๋๊ฐ ๋ง์์ ์ด์ง ์์ฌ์ด ์ฝ๋์ง๋ง, ์ฝ๋ ๊ฐ๋ตํ๋ก ์๊ฐ ์ฐ๊ธฐ๊ฐ ์ ๋งคํด์โฆใ
ใ