class Solution {
    public int[] solution(int brown, int yellow) {
        int[] answer = new int[2];
        int whM = brown+yellow;
        int whP = ((whM-yellow)/2)+2;
        
        for(int w=1;w<=brown; w++){
            for(int h=1; h<=w; h++){
                if(w+h==whP && w*h==whM){
                    answer[0]=w;
                    answer[1]=h;
                    break;
                }
            }
        }
        
        return answer;
    }
}

 

wh = brown+yellow

yellow = (w-2)*)(h-2) -> w+h = (wh+4-yellow)/2

 

돌면서 저 식 두개 만족하면 종료 ,,

 

'NOTE > 프로그래머스' 카테고리의 다른 글

신고 결과 받기  (0) 2022.05.10
베스트앨범  (0) 2022.04.04
등굣길  (0) 2022.03.30
N으로 표현  (0) 2022.03.29
Level2 - 가장 큰 정사각형 찾기  (0) 2022.03.16

+ Recent posts