https://programmers.co.kr/learn/courses/30/lessons/77484
νμ΄
lottos λ°°μ΄ λ΄ μ«μμ win_nums λ°°μ΄ λ΄ κ°μ μ«μ + lottos λ°°μ΄λ΄ 0μ μ«μ -> μ΅κ³ μμ
lottos λ°°μ΄ λ΄ μ«μμ win_nums λ°°μ΄ λ΄ κ°μ μ«μ -> μ΅μ μμ
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = {0,0};
int corNum = 0;
int zero = 0;
for(int i = 0; i < 6; i++){
if(lottos[i] == 0)
zero++;
for(int j = 0; j < 6; j++){
if(lottos[i] == win_nums[j]){
corNum++;
}
}
}
if(corNum + zero == 6){
answer[0] = 1;
}
else if(corNum + zero == 5)
answer[0] = 2;
else if(corNum + zero == 4)
answer[0] = 3;
else if(corNum + zero == 3)
answer[0] = 4;
else if(corNum + zero == 2)
answer[0] = 5;
else
answer[0] = 6;
if(corNum == 6)
answer[1] = 1;
else if(corNum == 5)
answer[1] = 2;
else if(corNum == 4)
answer[1] = 3;
else if(corNum == 3)
answer[1] = 4;
else if(corNum == 2)
answer[1] = 5;
else
answer[1] = 6;
return answer;
}
}
λ€μ 과격νκ³ λμ°ν μ½λκ° νμνμλ€. μ΄μ λν μμΈμ ν©μ λ±μλ‘ μΉννλ κ³Όμ μμ λ²μ΄μ§ μΌμ΄λ€. λ€λ₯Έ λΆλ€μ μ½λλ₯Ό λ³΄κ³ μ’ λ°°μ°μλ©΄ μλ μ λ μ½λκ° λ΄κ° μκ°ν λ¬Έμ λ₯Ό μ ν΄κ²°ν λ¬Έμ κ° μλκΉ λΌκ³ νλ¨λλ€.
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int[2];
int cnt1 = 0;
int cnt2 = 0;
for(int i : lottos) {
if(i == 0) {
cnt1++;
continue;
}
for(int j : win_nums) {
if(i == j) cnt2++;
}
}
answer[0] = getGrade(cnt1+cnt2);
answer[1] = getGrade(cnt2);
return answer;
}
public int getGrade(int n) {
switch(n) {
case 6 :
return 1;
case 5 :
return 2;
case 4 :
return 3;
case 3 :
return 4;
case 2 :
return 5;
default :
return 6;
}
}
}
int[] answer = {Math.min(7 - max, 6), Math.min(7 - min, 6)};
μλλ©΄ ν΄λΉ μμΌλ‘λ λ¬Έμ λ₯Ό ν μ μλ€. λ±μμ λν΄μ μ΄λ κ² ν μ λ μꡬλ..!
'μκ³ λ¦¬μ¦ νμ΄ > νλ‘κ·Έλλ¨Έμ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[νλ‘κ·Έλλ¨Έμ€]μΉ΄μΉ΄μ€ 2019 μΈν΄ - ν¬λ μΈ μΈνλ½κΈ° κ²μ μλ°νμ΄ (0) | 2021.01.10 |
---|