We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a0ba7a9 commit 708dd7cCopy full SHA for 708dd7c
src/0401-0500/492 - Construct the Rectangle/contruct_the_rectangle.rs
@@ -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