Skip to content

Commit 708dd7c

Browse files
committed
solved: 492. Construct the Rectangle
Signed-off-by: rajput-hemant <[email protected]>
1 parent a0ba7a9 commit 708dd7c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
impl Solution {
2+
pub fn construct_rectangle(area: i32) -> Vec<i32> {
3+
let mut w = (area as f64).sqrt() as i32;
4+
5+
// until the remainder is 0, decrement w
6+
// this will find the largest w that is a factor of area
7+
while area % w != 0 {
8+
w -= 1;
9+
}
10+
11+
// return the result
12+
vec![area / w, w]
13+
}
14+
}

0 commit comments

Comments
 (0)