Skip to content

K Closest Points To Origin#81

Open
Yuto729 wants to merge 1 commit into
mainfrom
k-closest-points-to-origin
Open

K Closest Points To Origin#81
Yuto729 wants to merge 1 commit into
mainfrom
k-closest-points-to-origin

Conversation

@Yuto729

@Yuto729 Yuto729 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

解く問題

K Closest Points To Origin

次に解く問題

Balanced Binary Tree

Repository owner deleted a comment from github-actions Bot Jun 22, 2026
k_closest_points = []
for point in points:
x, y = point[0], point[1]
heapq.heappush(k_closest_points, ((- (x ** 2 + y ** 2), x, y)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

イメージ的に累乗の計算は遅そうに感じます。 x * x 等、より軽そうな書き方ができるのであれば、そちらで書いたほうが良いように思います。ただ、 CPython の実装を読んでみないと実際に重いかどうかは分かりません。また、定数倍の差しかないため、そこを気にするのであれば Python より速い言語で書き直すことを視野に入れたほうが良いのだとも思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants