본문 바로가기
알고리즘

[Programmers] 카펫

by 슈슈슉민 2023. 6. 7.
class Solution {
    public int[] solution(int brown, int yellow) {
        int[] answer = new int[2];
        int sum = brown + yellow;

        for (int height = 3; height <= sum; height++) {
            if (sum % height == 0) {
                int width = sum / height;
                if ((width - 2) * (height - 2) == yellow) {
                    answer[0] = width;
                    answer[1] = height;
                    break;
                }
            }
        }
        
        return answer;
    }
}