Skip to content

Commit 8bbd95b

Browse files
Update algorithms/heap/topkclosesttoorigin/__init__.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent bb4ced1 commit 8bbd95b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

algorithms/heap/topkclosesttoorigin/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ def k_closest_to_origin(points: List[List[int]], k: int) -> List[List[int]]:
3131
def k_closest_to_origin_sorting(points: List[List[int]], k: int) -> List[List[int]]:
3232
# Sort the points by the distance from the origin. This incurs a cost of O(n log(n)) and space cost of O(n) due to
3333
# timsort
34-
points.sort(key=lambda p: p[0] ** 2 + p[1] ** 2)
34+
sorted_points = sorted(points, key=lambda p: p[0] ** 2 + p[1] ** 2)
3535
# Retrieve the top k points closest to the origin
36-
return points[:k]
36+
return sorted_points[:k]

0 commit comments

Comments
 (0)