Construct the Rectangle

  • 0

    We just have to start checking from the root of the area because doing that would ensure the condition that the length and breadth of rectangle would be as close as possible. While returning we have to make sure that the larger of the 2 numbers would come first.

    class Solution:
        def constructRectangle(self, area):
            :type area: int
            :rtype: List[int]
            root = int(area**0.5)
            for i in range(root,0,-1):
                if area % i == 0:
                    x = area // i
                    y = i
                    if x > y:
                        return [x,y]
                        return [y,x]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.