Skip to content

Commit 57e9703

Browse files
Formatting
1 parent 65cedc3 commit 57e9703

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/k_closest_points_to_origin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ class Solution:
1919
origin. Since the `heapq` module only provides an implementation for a min-
2020
heap, the distance is negated before being inserted into the heap.
2121
"""
22-
def kClosest(self, points: list[list[int]], k: int) -> list[list[int]]:
2322

23+
def kClosest(self, points: list[list[int]], k: int) -> list[list[int]]:
2424
heap: list[tuple[float, list[int]]] = [] # (distance, [xi,yi])
2525

2626
for i, p in enumerate(points):
27-
d = math.sqrt(p[0]**2 + p[1]**2)
27+
d = math.sqrt(p[0] ** 2 + p[1] ** 2)
2828
if i < k:
2929
heapq.heappush(heap, (-d, p))
30-
else:
31-
if -d > heap[0][0]:
32-
heapq.heapreplace(heap, (-d, p))
30+
elif -d > heap[0][0]:
31+
heapq.heapreplace(heap, (-d, p))
3332

3433
return [p[1] for p in heap]

0 commit comments

Comments
 (0)