Back to course home
0% completed
Vote For New Content
Why the official solution is so complicated??
Mohammed Dh Abbas
May 9, 2024
Why not
def findClosestPoints(self, points, k): result = [] min_heap = [] for point in points: heappush(min_heap, (point.distance_from_origin(), point)) for i in range(k): tup = heappop(min_heap) result.append([tup[1].x, tup[1].y]) return result
0
0
Comments
Comments
Riju Dattaa year ago
This solution is O(n log n), where n is the length of the points array, rather than simply being O(n log k) (k being the input parameter we're given) as the official solution provides. The loop "for point in points" iterates through every single element in points and pu...
On this page