第2天了。
今天的题目是[https://leetcode.com/problems/k-closest-points-to-origin/](K Closest Points to Origin):
We have a list of points
on the plane. Find the K
closest points to the origin (0, 0)
.
(Here, the distance between two points on a plane is the Euclidean distance.)
You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.)
Example 1:
Example 2:
Note:
1 <= K <= points.length <= 10000
-10000 < points[i][0] < 10000
-10000 < points[i][1] < 10000
今天的题目比较简单,虽然是一道Mediem
的题目,但是不知道为什么好像常规做法就AC了。解法就是算每个点到原点的距离先,然后排序,最后取出前K个就好了: