1828. Statistics the number of a circle mid -point One question daily
topic:
1828. Statistics the number of a circle mid -point
Thought:
Today's question is very simple,I wonder if it is against yesterday's question bidding。
AskqueriesThere are a few in the circlepointsPoints in an array。
To be honest, I was scared,I think this question is the question of the picture again。不过仔细读题了后发现只是一道简单的math题,
We can use European -style distance to solve(Time complexity isOn^2,I thought I had a better solution,At first glance everyone is like this())
The formula of the European -style distance is as follows:
We look at the code for specific operations:
Code
class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
# Seek to solve whether the European -style distance from the center is less than r
ans = [0] * len(queries)
flag = 0
for x, y, r in queries:
for i, j in points:
if ((x - i) ** 2 + (y - j) ** 2) ** (1 / 2) <= r:
ans[flag] += 1
flag += 1
return ansTake a look at someone who can't understandpythonCode:
class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
points = sorted(points)
res = [0 for _ in range(len(queries))]
for i, (u, v, r) in enumerate(queries):
left, right = u - r, u + r
idx1 = bisect_left(points, [left, -inf])
idx2 = bisect_right(points, [right, inf])
for x, y in points[idx1: idx2 + 1]:
if (v - r <= y <= v + r and
(x - u) * (x - u) + (y - v) * (y - v) <= r * r):
res[i] += 1
return res贡献者
最近更新
Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0
1825. Seek out MK average value
LeetCode 1825. 求出 MK 平均值 题解 — 使用三个 multiset 维护滑动窗口中的最小值、中间值和最大值集合,通过平衡插入与删除操作保持 lower 和 upper 各含 k 个元素,并实时维护 middle 的元素和以 O(log n) 计算剔除首尾 k 个后的平均值。适合准备系统设计面试或需要掌握有序集合与滑动窗口技巧的算法学习者。
219.Existing duplicate elements II Hash table graphics
LeetCode 219. 存在重复元素 II 题解 — 使用哈希表与滑动窗口双指针解法,核心技巧是维护一个长度不超过 k+1 的窗口,在窗口内快速检测重复元素。适合正在刷 LeetCode 数组与哈希表题目的求职者或算法学习者。