Skip to content

Commit 2a43472

Browse files
committedJul 24, 2017
edit 492
1 parent ab47ac5 commit 2a43472

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Your ideas/fixes/algorithms are more than welcome!
121121
|495|[Teemo Attacking](https://leetcode.com/problems/teemo-attacking/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_495.java) | O(n) |O(1) | Medium| Array
122122
|494|[Target Sum](https://leetcode.com/problems/target-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_494.java) | O(2^n) |O(1) | Medium|
123123
|493|[Reverse Pairs](https://leetcode.com/problems/reverse-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_493.java) | O(?) |O(?) | Hard|
124-
|492|[Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle/)|[Solution](../master/src/main/java/com/fishercoder/solutions/ConstructTheRectangle.java) | O(n) |O(1) | Easy| Array
124+
|492|[Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_492.java) | O(n) |O(1) | Easy| Array
125125
|491|[Increasing Subsequences](https://leetcode.com/problems/increasing-subsequences/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_491.java) | O(n!) |O(n) | Medium| Backtracking, DFS
126126
|490|[The Maze](https://leetcode.com/problems/the-maze/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_490.java) | O(m*n) |O(m*n) | Medium| BFS
127127
|488|[Zuma Game](https://leetcode.com/problems/zuma-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_488.java) | O(?) |O(?) | Hard | DFS, Backtracking

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
package com.fishercoder.solutions;
22

33
/**
4-
* For a web developer, it is very important 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:
4+
* For a web developer, it is very important to know how to design a web page's size.
5+
* So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page,
6+
* whose length L and width W satisfy the following requirements:
57
68
1. The area of the rectangular web page you designed must equal to the given target area.
7-
89
2. The width W should not be larger than the length L, which means L >= W.
9-
1010
3. The difference between length L and width W should be as small as possible.
11+
1112
You need to output the length L and the width W of the web page you designed in sequence.
1213
Example:
1314
Input: 4
1415
Output: [2, 2]
1516
Explanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1].
1617
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+
1719
Note:
1820
The given area won't exceed 10,000,000 and is a positive integer
1921
The web page's width and length you designed must be positive integers.
2022
21-
* Created by fishercoder on 1/25/17.
2223
*/
23-
public class ConstructTheRectangle {
24+
public class _492 {
2425

2526
public int[] constructRectangle(int area) {
2627
int i = 0, j = area;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.fishercoder;
22

3-
import com.fishercoder.solutions.ConstructTheRectangle;
3+
import com.fishercoder.solutions._492;
44
import org.junit.Before;
55
import org.junit.BeforeClass;
66
import org.junit.Test;
@@ -10,15 +10,15 @@
1010
/**
1111
* Created by fishercoder on 1/25/17.
1212
*/
13-
public class ConstructTheRectangleTest {
14-
private static ConstructTheRectangle test;
13+
public class _492Test {
14+
private static _492 test;
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 ConstructTheRectangle();
21+
test = new _492();
2222
}
2323

2424
@Before

0 commit comments

Comments
 (0)
Please sign in to comment.