Skip to content

Commit cea45e8

Browse files
committed
Removed abs() calls in distance on line 5.
1 parent 42a2695 commit cea45e8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

python/0973-k-closest-points-to-origin.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ class Solution:
22
def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
33
pts = []
44
for x, y in points:
5-
dist = (abs(x - 0) ** 2) + (abs(y - 0) ** 2)
6-
pts.append([dist, x, y])
7-
8-
res = []
5+
dist = x ** 2 + y ** 2
6+
pts.append((dist, x, y))
7+
98
heapq.heapify(pts)
10-
for i in range(k):
11-
dist, x, y = heapq.heappop(pts)
12-
res.append([x, y])
13-
return res
9+
res = []
10+
for _ in range(k):
11+
_, x, y = heapq.heappop(pts)
12+
res.append((x, y))
13+
return res

0 commit comments

Comments
 (0)