October 29, 2021

문제 : https://programmers.co.kr/learn/courses/30/lessons/42586

해설 : https://eatdeveloplove.tistory.com/105

나의 풀이

정확성: 38.5
효율성: 0.0
합계: 38.5 / 50
function solution(brown, yellow) {
    var answer = [];
    
    for(let i=0; i<=brown+yellow; i++) {
        if((brown+yellow)%i===0) {
        answer.push(i);
        }
    }
    if(answer.length%2 === 0) {
        let tmp = answer.length/2;
        return [answer[tmp], answer[tmp-1]]
    } else {
        let tmp = Math.floor(answer.length/2)
        return [answer[tmp],answer[tmp]];
    }
}

남의 풀이

function solution(brown, yellow) {
    const sum = (brown / 2) + 2;
    for(let len = 3; (2 * len) <= sum; len++){
        if((len - 2)*(sum-len-2)==yellow) return [sum-len, len];
    }
}