class Solution {
public int[] solution(int brown, int yellow) {
int[] answer = new int[2];
int cnt = 0;
// yellow로 가로x세로 모든 조합을 찾는다
int limit = (int)Math.sqrt(yellow);
for(int i=1; i<= limit; i++){
if(yellow % i == 0){
// i가 작고 몫이 길다
int wid = yellow / i; // 몫
cnt = (i*2) + (wid*2) + 4; // 가로 칸 + 세로 칸 + 꼭짓점 칸
if(cnt == brown){
answer[0] = wid+2;
answer[1] = i+2;
break;
}
}
}
return answer;
}
}
'알고리즘 > 완전탐색' 카테고리의 다른 글
[프로그래머스 연습문제 level_2 ] 소수찾기 (0) | 2024.01.18 |
---|---|
[프로그래머스 연습문제 level_1 ] 모의고사 (0) | 2024.01.18 |
[프로그래머스 연습문제 level_1 ] 최소직사각형 (0) | 2024.01.15 |