

완전탐색 > 카펫
using System;
public class Solution
{
public int[] solution(int brown, int yellow)
{
// 전체 타일 수 계산
int total = brown + yellow;
// 3x3 부터니 i = 3 부터 시작해서 total의 제곱근까지
for(int i = 3; i <= (int)Math.Sqrt(total); i++)
{
// 나누어 떨어지믄
if(total % i == 0)
{
// 가로 길이 계산
int width = total / i;
// 노란색 타일 크기 체크
if((width - 2) * (i - 2) == yellow)
return new int[] {width,i};
}
}
return new int[0];
}
}
슬 눈에 들어오는 것 같으면서도 아닙니다..