728x90
2023.07.15 - [Coding Test/programmers] - 카펫
class Solution {
public int[] solution(int brown, int yellow) {
// 갈색 = w*2 + (h-2)*2 = (w+h-2)*2
// 노란색 = w*h-(w+h-2)*2
for (int w=3; w<=5000; w++){
for (int h=3; h<=w; h++){
int boundary = (w+h-2)*2;
int center = w*h-(w+h-2)*2;
if (brown==boundary && yellow==center)
return new int[] {w,h};
}
}
return null;
}
}
728x90