Skip to content

Commit 7a97f9e

Browse files
committedApr 13, 2025
Add solution #1401
1 parent 5427f19 commit 7a97f9e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-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,281 LeetCode solutions in JavaScript
1+
# 1,282 LeetCode solutions in JavaScript
22

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

@@ -1069,6 +1069,7 @@
10691069
1397|[Find All Good Strings](./solutions/1397-find-all-good-strings.js)|Hard|
10701070
1399|[Count Largest Group](./solutions/1399-count-largest-group.js)|Easy|
10711071
1400|[Construct K Palindrome Strings](./solutions/1400-construct-k-palindrome-strings.js)|Medium|
1072+
1401|[Circle and Rectangle Overlapping](./solutions/1401-circle-and-rectangle-overlapping.js)|Medium|
10721073
1402|[Reducing Dishes](./solutions/1402-reducing-dishes.js)|Hard|
10731074
1408|[String Matching in an Array](./solutions/1408-string-matching-in-an-array.js)|Easy|
10741075
1410|[HTML Entity Parser](./solutions/1410-html-entity-parser.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1401. Circle and Rectangle Overlapping
3+
* https://leetcode.com/problems/circle-and-rectangle-overlapping/
4+
* Difficulty: Medium
5+
*
6+
* You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle
7+
* represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner,
8+
* and (x2, y2) are the coordinates of the top-right corner of the rectangle.
9+
*
10+
* Return true if the circle and rectangle are overlapped otherwise return false. In other words,
11+
* check if there is any point (xi, yi) that belongs to the circle and the rectangle at the same
12+
* time.
13+
*/
14+
15+
/**
16+
* @param {number} radius
17+
* @param {number} xCenter
18+
* @param {number} yCenter
19+
* @param {number} x1
20+
* @param {number} y1
21+
* @param {number} x2
22+
* @param {number} y2
23+
* @return {boolean}
24+
*/
25+
var checkOverlap = function(radius, xCenter, yCenter, x1, y1, x2, y2) {
26+
const closestX = Math.max(x1, Math.min(x2, xCenter));
27+
const closestY = Math.max(y1, Math.min(y2, yCenter));
28+
29+
return ((xCenter - closestX) ** 2 + (yCenter - closestY) ** 2) <= radius ** 2;
30+
};

0 commit comments

Comments
 (0)
Please sign in to comment.