K Closest Points to Origin

Problem Id: 973 Difficulty: Medium


Intuition

Solution


class Solution:
    def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]:
        points.sort(key=lambda x: x[0] * x[0] + x[1] * x[1])
        return points[:K]