Created
August 9, 2017 08:52
-
-
Save luojiyin1987/a25732085692dda588da53a48d0d0836 to your computer and use it in GitHub Desktop.
Construct the Rectangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func constructRectangle(area int) []int { | |
| res := 1 | |
| for i := 2; i * i <= area; i++ { | |
| if area % i == 0 { | |
| res = i | |
| } | |
| } | |
| return []int{area / res, res} | |
| } | |
| func constructRectangle(area int) []int { | |
| var temp []int | |
| x := int(math.Sqrt(float64(area))) | |
| if x * x == area { | |
| temp = append(temp, x) | |
| temp = append(temp, x) | |
| } else { | |
| for i :=x ; ;i++ { | |
| if area % i == 0 { | |
| if area / i > i { | |
| temp =append(temp , area/i) | |
| temp =append(temp, i) | |
| } else { | |
| temp = append(temp, i) | |
| temp = append(temp,area/i) | |
| } | |
| break | |
| } | |
| } | |
| } | |
| return temp | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment