Given some points and an origin point in two-dimensional space, find k points which are nearest to the origin.
Return these points sorted by distance, if they are same in distance, sorted by the x-axis, and if they are same in the x-axis, sorted by y-axis.
Example
No.1
Input: points = [[4,6],[4,7],[4,4],[2,5],[1,1]], origin = [0, 0], k = 3
Output: [[1,1],[2,5],[4,4]]
No.2
Input: points = [[0,0],[0,9]], origin = [3, 1], k = 1
Output: [[0,0]]
Code
1 | public class Point { |
1 | public Point[] kClosest(Point[] points, Point origin, int k) { |