Skip to content

Commit 1624ec5

Browse files
solves number of rectangles that can form largest square
1 parent 6f666d8 commit 1624ec5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
| 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | [![Java](assets/java.png)](src/MaximumUnitsOnATruck.java) | |
424424
| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | [![Java](assets/java.png)](src/CalculateMoneyInLeetCodeBank.java) | |
425425
| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | [![Java](assets/java.png)](src/DecodeXORedArray.java) | |
426-
| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | | |
426+
| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | [![Java](assets/java.png)](src/NumberOfRectanglesThatCanFormTheLargestSquare.java) | |
427427
| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | | |
428428
| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | | |
429429
| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | | |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class NumberOfRectanglesThatCanFormTheLargestSquare {
2+
public int countGoodRectangles(int[][] rectangles) {
3+
int maxLength = 0, frequency = 0, length;
4+
for (int[] rectangle : rectangles) {
5+
length = Math.min(rectangle[0], rectangle[1]);
6+
if (length > maxLength) {
7+
maxLength = length;
8+
frequency = 1;
9+
} else if (length == maxLength) {
10+
frequency++;
11+
}
12+
}
13+
return frequency;
14+
}
15+
}

0 commit comments

Comments
 (0)