Python3 Solution


  • 0
    H

    A square is a special rectangle, and for the same area, the width of square is always smaller than the height of rectangle(sometimes equal to the height), so if we start from the width of square, the time would save a lot.

    class Solution:
        def constructRectangle(self, area):
            """
            :type area: int
            :rtype: List[int]
            """
            W = int(math.sqrt(area))
            for i in range(W,0,-1):
                if area % i == 0:
                    return([int(area / i),i])
            return []
    

Log in to reply
 

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