Skip to content

Commit 7f538d0

Browse files
committed
feat: add solutions to lc problem: No.1725
No.1725.Number Of Rectangles That Can Form The Largest Square
1 parent 9d2df6f commit 7f538d0

File tree

6 files changed

+189
-2
lines changed

6 files changed

+189
-2
lines changed

solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,80 @@
5454
<!-- 这里可写当前语言的特殊实现逻辑 -->
5555

5656
```python
57-
57+
class Solution:
58+
def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
59+
ans = mx = 0
60+
for l, w in rectangles:
61+
t = min(l, w)
62+
if mx < t:
63+
mx, ans = t, 1
64+
elif mx == t:
65+
ans += 1
66+
return ans
5867
```
5968

6069
### **Java**
6170

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

6473
```java
74+
class Solution {
75+
public int countGoodRectangles(int[][] rectangles) {
76+
int ans = 0, mx = 0;
77+
for (int[] r : rectangles) {
78+
int t = Math.min(r[0], r[1]);
79+
if (mx < t) {
80+
mx = t;
81+
ans = 1;
82+
} else if (mx == t) {
83+
++ans;
84+
}
85+
}
86+
return ans;
87+
}
88+
}
89+
```
90+
91+
### **C++**
92+
93+
```cpp
94+
class Solution {
95+
public:
96+
int countGoodRectangles(vector<vector<int>>& rectangles) {
97+
int ans = 0, mx = 0;
98+
for (auto& r : rectangles)
99+
{
100+
int t = min(r[0], r[1]);
101+
if (mx < t)
102+
{
103+
mx = t;
104+
ans = 1;
105+
}
106+
else if (mx == t) ++ans;
107+
}
108+
return ans;
109+
}
110+
};
111+
```
65112
113+
### **Go**
114+
115+
```go
116+
func countGoodRectangles(rectangles [][]int) int {
117+
ans, mx := 0, 0
118+
for _, r := range rectangles {
119+
t := r[0]
120+
if t > r[1] {
121+
t = r[1]
122+
}
123+
if mx < t {
124+
mx, ans = t, 1
125+
} else if mx == t {
126+
ans++
127+
}
128+
}
129+
return ans
130+
}
66131
```
67132

68133
### **...**

solution/1700-1799/1725.Number Of Rectangles That Can Form The Largest Square/README_EN.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,78 @@ The largest possible square is of length 5, and you can get it out of 3 rectangl
5656
### **Python3**
5757

5858
```python
59-
59+
class Solution:
60+
def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
61+
ans = mx = 0
62+
for l, w in rectangles:
63+
t = min(l, w)
64+
if mx < t:
65+
mx, ans = t, 1
66+
elif mx == t:
67+
ans += 1
68+
return ans
6069
```
6170

6271
### **Java**
6372

6473
```java
74+
class Solution {
75+
public int countGoodRectangles(int[][] rectangles) {
76+
int ans = 0, mx = 0;
77+
for (int[] r : rectangles) {
78+
int t = Math.min(r[0], r[1]);
79+
if (mx < t) {
80+
mx = t;
81+
ans = 1;
82+
} else if (mx == t) {
83+
++ans;
84+
}
85+
}
86+
return ans;
87+
}
88+
}
89+
```
90+
91+
### **C++**
92+
93+
```cpp
94+
class Solution {
95+
public:
96+
int countGoodRectangles(vector<vector<int>>& rectangles) {
97+
int ans = 0, mx = 0;
98+
for (auto& r : rectangles)
99+
{
100+
int t = min(r[0], r[1]);
101+
if (mx < t)
102+
{
103+
mx = t;
104+
ans = 1;
105+
}
106+
else if (mx == t) ++ans;
107+
}
108+
return ans;
109+
}
110+
};
111+
```
65112
113+
### **Go**
114+
115+
```go
116+
func countGoodRectangles(rectangles [][]int) int {
117+
ans, mx := 0, 0
118+
for _, r := range rectangles {
119+
t := r[0]
120+
if t > r[1] {
121+
t = r[1]
122+
}
123+
if mx < t {
124+
mx, ans = t, 1
125+
} else if mx == t {
126+
ans++
127+
}
128+
}
129+
return ans
130+
}
66131
```
67132

68133
### **...**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int countGoodRectangles(vector<vector<int>>& rectangles) {
4+
int ans = 0, mx = 0;
5+
for (auto& r : rectangles)
6+
{
7+
int t = min(r[0], r[1]);
8+
if (mx < t)
9+
{
10+
mx = t;
11+
ans = 1;
12+
}
13+
else if (mx == t) ++ans;
14+
}
15+
return ans;
16+
}
17+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func countGoodRectangles(rectangles [][]int) int {
2+
ans, mx := 0, 0
3+
for _, r := range rectangles {
4+
t := r[0]
5+
if t > r[1] {
6+
t = r[1]
7+
}
8+
if mx < t {
9+
mx, ans = t, 1
10+
} else if mx == t {
11+
ans++
12+
}
13+
}
14+
return ans
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int countGoodRectangles(int[][] rectangles) {
3+
int ans = 0, mx = 0;
4+
for (int[] r : rectangles) {
5+
int t = Math.min(r[0], r[1]);
6+
if (mx < t) {
7+
mx = t;
8+
ans = 1;
9+
} else if (mx == t) {
10+
++ans;
11+
}
12+
}
13+
return ans;
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
3+
ans = mx = 0
4+
for l, w in rectangles:
5+
t = min(l, w)
6+
if mx < t:
7+
mx, ans = t, 1
8+
elif mx == t:
9+
ans += 1
10+
return ans

0 commit comments

Comments
 (0)