492. Construct the Rectangle Easy
1/**
2 * [492] Construct the Rectangle
3 *
4 * A web developer needs to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:
5 * <ol>
6 * The area of the rectangular web page you designed must equal to the given target area.
7 * The width W should not be larger than the length L, which means L >= W.
8 * The difference between length L and width W should be as small as possible.
9 * </ol>
10 * Return an array [L, W] where L and W are the length and width of the web page you designed in sequence.
11 *
12 * Example 1:
13 *
14 * Input: area = 4
15 * Output: [2,2]
16 * Explanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1].
17 * But according to requirement 2, [1,4] is illegal; according to requirement 3, [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2.
18 *
19 * Example 2:
20 *
21 * Input: area = 37
22 * Output: [37,1]
23 *
24 * Example 3:
25 *
26 * Input: area = 122122
27 * Output: [427,286]
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= area <= 10^7
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/construct-the-rectangle/
38// discuss: https://leetcode.com/problems/construct-the-rectangle/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn construct_rectangle(area: i32) -> Vec<i32> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_492() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.