문제 설명
머쓱이는 직육면체 모양의 상자를 하나 가지고 있는데 이 상자에 정육면체 모양의 주사위를 최대한 많이 채우고 싶습니다. 상자의 가로, 세로, 높이가 저장되어있는 배열 box와 주사위 모서리의 길이 정수 n이 매개변수로 주어졌을 때, 상자에 들어갈 수 있는 주사위의 최대 개수를 return 하도록 solution 함수를 완성해주세요.
입출력 예
나의 풀이
class Solution {
public int solution(int[] box, int n) {
int answer = 1;
for(int i = 0; i < box.length; i++){
answer *= (int)Math.floor(box[i] / n);
}
return answer;
}
}
참고 풀이 (가장 보편)
class Solution {
public int solution(int[] box, int n) {
return (box[0] / n) * (box[1] / n) * (box[2] / n);
}
}
나의 풀이
function solution(box, n) {
let answer = 1;
for(let i = 0; i < box.length; i++){
answer *= parseInt(box[i] / n);
}
return answer;
}
참고 풀이 (구조분해 할당)
function solution(box, n) {
let [width, length, height] = box;
return Math.floor(width / n) * Math.floor(length / n) * Math.floor(height / n);
}