- 난이도: Lv2
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/42842
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/2/카펫
풀이 시간 : 1시간 12분
class Solution {
public int[] solution(int brown, int yellow) {
int totalArea = brown + yellow;
for (int width = 3; width <= totalArea / 3; width++) {
if (totalArea % width == 0) {
int height = totalArea / width;
if ((width - 2) * (height - 2) == yellow) {
return new int[] {Math.max(width, height), Math.min(width, height)};
}
}
}
return null;
}
}