공부기록/프로그래머스

[프로그래머스] 카펫

메델 2023. 11. 9. 19:30
class Solution {
    public int[] solution(int brown, int yellow) {
        int[] answer = new int[2];
        int sum = brown + yellow;
        
        for(int i=1; i<= sum; i++){
            int row = sum/i;
            int col = i;
            
            int yB = (row-2)* (col-2);
            
            if(col> row){
                break;
            }
            
            if(yB == yellow){
                answer[0] = row;
                answer[1] = col;
                break;
            }
            
        }
        
        return answer;
    }
}