Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

dearbeany

[프로그래머스] 카펫 본문

Algorithm

[프로그래머스] 카펫

dearbeany 2023. 11. 24. 22:26
class Solution {
    public int[] solution(int brown, int yellow) {
        int[] answer = new int[2];
        int sum = brown + yellow;
        int w = 0; // 가로  
        int h = 0; // 세로 
        
        for(int i = 3; i < sum; i++) {
            w = sum / i;
            if(yellow == (w-2)*(i-2)){
                answer[0] = w;
                answer[1] = i;
                break;
            }
        }
        
        return answer;
    }
}