
class Solution {
public int[] solution(int brown, int yellow) {
int[] answer = new int [2];
int total = brown + yellow;
for(int i = 3; i < total / 3 + 1; i++) {
if(total % i == 0) {
int width = total / i;
if((i - 2) * width - ((i - 2) * 2) == yellow) {
answer[0] = width;
answer[1] = i;
return answer;
}
}
}
return answer;
}
}
문제 제한 사항에서 힌트를 찾을 수 있다.
위 두개의 힌트로 카펫의 높이는 무조건 3 이상이여야 한다는 것과 answer[0] > answer[1]이다는 것을 알아 낼수 있다.