---
# System prepended metadata

title: \#492 Construct the Rectangle
tags: [leetcode, leetcode-easy]

---

# \#492 Construct the Rectangle
## *給定一數area, 回傳整數陣列[L,W]滿足 L>W 且 L\*W=area 且L與W的差最小*
## Log
 - build 20210919 by syhuang

## 改良版
 - t從area的平方根開始跑迴圈
 - leetcode submit runtime 58%, memory 76%
```javascript=
var constructRectangle = function(area) {
    let W=1,L=area;
    for(let t = Math.floor(Math.sqrt(area)); t>1; t--){
        if(area%t==0){
            W = t;
            L = area/t;
            break;
        }
    }
    return [L,W];
};
```
## 初見
 - 土法煉鋼跑迴圈求L和W, t=2開始直到t>area的平方根為止
 - leetcode submit runtime 58%, memory 15%
```javascript=
var constructRectangle = function(area) {
    let L=area,W=1;
    let tArea = area;
    for(let t=2; t<=Math.sqrt(area); t++){
        if(area%t==0){
            W = t;
            L = area/t;
        }
    }
    return [L,W];
};
```
## 備註
## 參考
###### tags: `leetcode`, `leetcode-easy`