본문 바로가기

Coding Test/프로그래머스

[프로그래머스/자바] 카펫

class Solution {
    public int[] solution(int brown, int yellow) {
        int tmp1 = brown / 2 - 1;
        int tmp2 = (brown - (tmp1 * 2)) / 2;
        
        while (true) {
            if ((tmp1 - 2) * tmp2 == yellow) return new int[]{tmp1, tmp2 + 2};
            else {
                tmp1 -= 1;
                tmp2 = (brown - (tmp1 * 2)) / 2;
            }
        }
    }
}