Leo가 본 카펫에서 갈색 격자의 수 brown, 노란색 격자의 수 yellow가 매개변수로 주어질 때 카펫의 가로, 세로 크기를 순서대로 배열에 담아 return 하도록 solution 함수를 작성해주세요.
[제곱근, 제곱근]
형태의 배열을 반환하는 함수를 작성하면 된다.import Foundation
func solution(_ brown:Int, _ yellow:Int) -> [Int] {
let total = brown + yellow
var x = 0, y = 0, result = [Int]()
for i in 1...total {
if total % i == 0 {
x = i
y = total / i
if (x - 2) * (y - 2) == yellow {
break
}
}
}
result = [x, y]
return result.sorted(by: >)
}