728x90
2023.07.15 - [Coding Test/programmers] - 카펫
카펫
프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solutio
karla.tistory.com
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