https://programmers.co.kr/learn/courses/30/lessons/42842
function solution(brown, yellow) {
const cand = [];
const size = brown + yellow;
for (var r = 3; r <= Math.sqrt(size); r++)
if (size % r === 0)
cand.push([size / r, r])
return cand.filter(([a, b]) => 2 * (a + b) - 4 === brown)[0];
}
어짜피 정답은 하나 뿐이니 코드 최적화
function solution(brown, yellow) {
const size = brown + yellow;
var row = 3;
while(row <= Math.sqrt(size)){
if(size % row === 0 && 2 * (size/row + row) - 4 === brown)
break;
row++;
}
return [size/row, row];
}