1014. K Closest Points to Origin
My accepted Python solution to LeetCode problem 1014, K Closest Points to Origin, running in 34ms.
- Difficulty: Medium
- Python
- Runtime 34ms
- Memory 21.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 34ms, memory 21.6MB, accepted 2026-01-02.
class Solution:
def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
# Sort by distance squared (no need for sqrt)
points.sort(key=lambda p: p[0]**2 + p[1]**2)
return points[:k]