Contents
내가 작성한 코드
내가 작성한 코드
class Solution {
public int solution(int a, int b, int c, int d) {
int[] dice = { a, b, c, d };
int[] counts = new int[7];
// 주사위 눈금 개수 세기
for (int num : dice) {
counts[num]++;
}
// 주사위 경우의 수 체크
for (int p = 1; p <= 6; p++) {
// 4개가 같을 때
if (counts[p] == 4) {
return 1111 * p;
}
// 3개가 같을 때
if (counts[p] == 3) {
for (int q = 1; q <= 6; q++) {
if (counts[q] == 1) {
return (10 * p + q) * (10 * p + q);
}
}
}
// 2+2 또는 2+1+1
if (counts[p] == 2) {
for (int q = 1; q <= 6; q++) {
if (counts[q] == 2 && p != q) { // 2+2
return (p + q) * Math.abs(p - q);
}
if (counts[q] == 1) { // 2+1+1
for (int r = 1; r <= 6; r++) {
if (counts[r] == 1 && q != r) {
return q * r;
}
}
}
}
}
}
// 4개가 다 다를 때 (최소값 찾기)
int min = 7;
for (int p = 1; p <= 6; p++) {
if (counts[p] == 1) {
min = Math.min(min, p);
}
}
return min;
}
}
Share article