LeetCode-973 K Closest Points to Origin Solution (with Java)

1. Description:


Notes:

2. Examples:

3.Solutions:

 1 /**
 2  * Created by sheepcore on 2019-02-24
 3  */
 4 class Solution {
 5     public int[][] kClosest(int[][] points, int K) {
 6          Arrays.sort(points, (p1, p2) -> p1[0] * p1[0] + p1[1] * p1[1] - p2[0] * p2[0] - p2[1] * p2[1]);
 7          return Arrays.copyOfRange(points, 0, K);
 8     } 
10 }

 

原文地址:https://www.cnblogs.com/sheepcore/p/12396220.html