LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 34ms, memory 21.6MB, accepted 2026-01-02.

python
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]

Source