Files
LeetCode-Go/leetcode/0492.Construct-the-Rectangle/492.Construct the Rectangle.go
2021-11-06 19:18:25 -07:00

17 lines
236 B
Go

package leetcode
import "math"
func constructRectangle(area int) []int {
ans := make([]int, 2)
W := int(math.Sqrt(float64(area)))
for W >= 1 {
if area%W == 0 {
ans[0], ans[1] = area/W, W
break
}
W -= 1
}
return ans
}