Skip to content

Commit 7ef7a21

Browse files
refactor 492
1 parent dd08bf7 commit 7ef7a21

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/main/java/com/fishercoder/solutions/_492.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fishercoder.solutions;
22

33
/**
4+
* 492. Construct the Rectangle
5+
*
46
* For a web developer, it is very important to know how to design a web page's size.
57
* So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page,
68
* whose length L and width W satisfy the following requirements:
@@ -23,22 +25,24 @@
2325
*/
2426
public class _492 {
2527

26-
public int[] constructRectangle(int area) {
27-
int i = 0;
28-
int j = area;
29-
int[] result = new int[2];
30-
while (i <= j) {
31-
long product = i * j;
32-
if (product == area) {
33-
result[0] = j--;
34-
result[1] = i++;
35-
} else if (product > area) {
36-
j--;
37-
} else {
38-
i++;
28+
public static class Solution1 {
29+
public int[] constructRectangle(int area) {
30+
int i = 0;
31+
int j = area;
32+
int[] result = new int[2];
33+
while (i <= j) {
34+
long product = i * j;
35+
if (product == area) {
36+
result[0] = j--;
37+
result[1] = i++;
38+
} else if (product > area) {
39+
j--;
40+
} else {
41+
i++;
42+
}
3943
}
44+
return result;
4045
}
41-
return result;
4246
}
4347

4448
}

src/test/java/com/fishercoder/_492Test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
* Created by fishercoder on 1/25/17.
1212
*/
1313
public class _492Test {
14-
private static _492 test;
14+
private static _492.Solution1 solution1;
1515
private static int[] expected;
1616
private static int[] actual;
1717
private static int area;
1818

1919
@BeforeClass
2020
public static void setup() {
21-
test = new _492();
21+
solution1 = new _492.Solution1();
2222
}
2323

2424
@Before
@@ -32,15 +32,15 @@ public void setupForEachTest() {
3232
public void test1() {
3333
area = 4;
3434
expected = new int[]{2, 2};
35-
actual = test.constructRectangle(area);
35+
actual = solution1.constructRectangle(area);
3636
assertArrayEquals(expected, actual);
3737
}
3838

3939
@Test
4040
public void test2() {
4141
area = 3;
4242
expected = new int[]{3, 1};
43-
actual = test.constructRectangle(area);
43+
actual = solution1.constructRectangle(area);
4444
assertArrayEquals(expected, actual);
4545
}
4646
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy