492. Construct the Rectangle

xiaoxiao2021-02-28  139

class Solution(object): def constructRectangle(self, area): """ :type area: int :rtype: List[int] """ l = [] i = math.floor(math.sqrt(area)) while (i > 0): if area % i == 0: l.append(int(area/i)) l.append(int(i)) return l i -= 1

math.floor()返回的是小数,所以需要加一个整型转换;

可以不需要向下取整,int(math.sqrt(area))就是取整数部分

转载请注明原文地址: https://www.6miu.com/read-18325.html

最新回复(0)