MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / construct_rectangle

Method construct_rectangle

492-construct-the-rectangle.rs:4–25  ·  view source on GitHub ↗
(area: i32)

Source from the content-addressed store, hash-verified

2
3impl Solution {
4 pub fn construct_rectangle(area: i32) -> Vec<i32> {
5 let mut ret = vec!(0; 2);
6 let mut cha = 10000000;
7 for i in 1..=area/2+1 {
8 if area % i == 0 {
9 let tmp = area / i;
10 let abs = (tmp - i).abs();
11 if abs > cha {
12 continue;
13 }
14 cha = abs;
15 if tmp > i {
16 ret[0] = tmp;
17 ret[1] = i;
18 } else {
19 ret[0] = i;
20 ret[1] = tmp;
21 }
22 }
23 }
24 ret
25 }
26}
27
28fn main() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected