Skip to content

Commit c198662

Browse files
committedFeb 6, 2021
feat: add python and java solutions to leetcode problem: No.0492
1 parent c251452 commit c198662

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed
 

‎index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
hook.afterEach(function (html) {
8484
const en = vm.route.file.indexOf('README_EN') != -1
8585
const copyright = en ? '. All Rights Reserved' : ' 版权所有'
86-
const footer = `<footer><span>Copyright © 2018-2020 <a href="https://github.com/doocs" target="_blank">Doocs</a>${copyright}</footer>`
86+
const footer = `<footer><span>Copyright © 2018-2021 <a href="https://github.com/doocs" target="_blank">Doocs</a>${copyright}</footer>`
8787
return html + footer
8888
})
8989
},

‎solution/0400-0499/0492.Construct the Rectangle/README.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,39 @@
4444
<!-- 这里可写当前语言的特殊实现逻辑 -->
4545

4646
```python
47-
47+
class Solution:
48+
def constructRectangle(self, area: int) -> List[int]:
49+
sr = int(math.sqrt(area))
50+
l = w = sr
51+
while l <= area and w >= 1:
52+
s = l * w
53+
if s == area:
54+
break
55+
if s > area:
56+
w -= 1
57+
else:
58+
l += 1
59+
return [l, w]
4860
```
4961

5062
### **Java**
5163

5264
<!-- 这里可写当前语言的特殊实现逻辑 -->
5365

5466
```java
55-
67+
class Solution {
68+
public int[] constructRectangle(int area) {
69+
int sr = (int) Math.sqrt(area);
70+
int l = sr, w = sr;
71+
while (l <= area && w >= 1) {
72+
int s = l * w;
73+
if (s == area) break;
74+
if (s > area) --w;
75+
else ++l;
76+
}
77+
return new int[]{l, w};
78+
}
79+
}
5680
```
5781

5882
### **...**

‎solution/0400-0499/0492.Construct the Rectangle/README_EN.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,37 @@ But according to requirement 2, [1,4] is illegal; according to requirement 3, [
5555
### **Python3**
5656

5757
```python
58-
58+
class Solution:
59+
def constructRectangle(self, area: int) -> List[int]:
60+
sr = int(math.sqrt(area))
61+
l = w = sr
62+
while l <= area and w >= 1:
63+
s = l * w
64+
if s == area:
65+
break
66+
if s > area:
67+
w -= 1
68+
else:
69+
l += 1
70+
return [l, w]
5971
```
6072

6173
### **Java**
6274

6375
```java
64-
76+
class Solution {
77+
public int[] constructRectangle(int area) {
78+
int sr = (int) Math.sqrt(area);
79+
int l = sr, w = sr;
80+
while (l <= area && w >= 1) {
81+
int s = l * w;
82+
if (s == area) break;
83+
if (s > area) --w;
84+
else ++l;
85+
}
86+
return new int[]{l, w};
87+
}
88+
}
6589
```
6690

6791
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int[] constructRectangle(int area) {
3+
int sr = (int) Math.sqrt(area);
4+
int l = sr, w = sr;
5+
while (l <= area && w >= 1) {
6+
int s = l * w;
7+
if (s == area) break;
8+
if (s > area) --w;
9+
else ++l;
10+
}
11+
return new int[]{l, w};
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def constructRectangle(self, area: int) -> List[int]:
3+
sr = int(math.sqrt(area))
4+
l = w = sr
5+
while l <= area and w >= 1:
6+
s = l * w
7+
if s == area:
8+
break
9+
if s > area:
10+
w -= 1
11+
else:
12+
l += 1
13+
return [l, w]

0 commit comments

Comments
 (0)