File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * 492. Construct the Rectangle
3+ * https://leetcode.com/problems/construct-the-rectangle/
4+ * Difficulty: Easy
5+ *
6+ * A web developer needs to know how to design a web page's size. So, given
7+ * a specific rectangular web page’s area, your job by now is to design a
8+ * rectangular web page, whose length L and width W satisfy the following
9+ * requirements:
10+ *
11+ * The area of the rectangular web page you designed must equal to the given
12+ * target area. The width W should not be larger than the length L, which
13+ * means L >= W. The difference between length L and width W should be as
14+ * small as possible.
15+ *
16+ * Return an array [L, W] where L and W are the length and width of the web
17+ * page you designed in sequence.
18+ */
19+
20+ /**
21+ * @param {number } area
22+ * @return {number[] }
23+ */
24+ var constructRectangle = function ( area ) {
25+ let width = Math . floor ( Math . sqrt ( area ) ) ;
26+ while ( area % width ) {
27+ width -- ;
28+ }
29+ return [ area / width , width ] ;
30+ } ;
Original file line number Diff line number Diff line change 161161463|[ Island Perimeter] ( ./0463-island-perimeter.js ) |Medium|
162162476|[ Number Complement] ( ./0476-number-complement.js ) |Easy|
163163491|[ Non-decreasing Subsequences] ( ./0491-non-decreasing-subsequences.js ) |Medium|
164+ 492|[ Construct the Rectangle] ( ./0492-construct-the-rectangle.js ) |Easy|
164165500|[ Keyboard Row] ( ./0500-keyboard-row.js ) |Easy|
165166506|[ Relative Ranks] ( ./0506-relative-ranks.js ) |Easy|
166167509|[ Fibonacci Number] ( ./0509-fibonacci-number.js ) |Easy|
You can’t perform that action at this time.
0 commit comments