Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6bd096b

Browse files
committed
Add solution #1725
1 parent d974b9e commit 6bd096b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,502 LeetCode solutions in JavaScript
1+
# 1,503 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1329,6 +1329,7 @@
13291329
1721|[Swapping Nodes in a Linked List](./solutions/1721-swapping-nodes-in-a-linked-list.js)|Medium|
13301330
1722|[Minimize Hamming Distance After Swap Operations](./solutions/1722-minimize-hamming-distance-after-swap-operations.js)|Medium|
13311331
1723|[Find Minimum Time to Finish All Jobs](./solutions/1723-find-minimum-time-to-finish-all-jobs.js)|Hard|
1332+
1725|[Number Of Rectangles That Can Form The Largest Square](./solutions/1725-number-of-rectangles-that-can-form-the-largest-square.js)|Easy|
13321333
1726|[Tuple with Same Product](./solutions/1726-tuple-with-same-product.js)|Medium|
13331334
1732|[Find the Highest Altitude](./solutions/1732-find-the-highest-altitude.js)|Easy|
13341335
1748|[Sum of Unique Elements](./solutions/1748-sum-of-unique-elements.js)|Easy|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 1725. Number Of Rectangles That Can Form The Largest Square
3+
* https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/
4+
* Difficulty: Easy
5+
*
6+
* You are given an array rectangles where rectangles[i] = [li, wi] represents the ith rectangle
7+
* of length li and width wi.
8+
*
9+
* You can cut the ith rectangle to form a square with a side length of k if both k <= li and
10+
* k <= wi. For example, if you have a rectangle [4,6], you can cut it to get a square with a
11+
* side length of at most 4.
12+
*
13+
* Let maxLen be the side length of the largest square you can obtain from any of the given
14+
* rectangles.
15+
*
16+
* Return the number of rectangles that can make a square with a side length of maxLen.
17+
*/
18+
19+
/**
20+
* @param {number[][]} rectangles
21+
* @return {number}
22+
*/
23+
var countGoodRectangles = function(rectangles) {
24+
let maxSide = 0;
25+
let result = 0;
26+
27+
for (const [length, width] of rectangles) {
28+
const side = Math.min(length, width);
29+
if (side > maxSide) {
30+
maxSide = side;
31+
result = 1;
32+
} else if (side === maxSide) {
33+
result++;
34+
}
35+
}
36+
37+
return result;
38+
};

0 commit comments

Comments
 (0)