java System.arraycopy()使用方法

    技术2025-02-14  19

    System.arraycopy(src, srcPos, dest, destPos, length) src: 源数组,数据是从这个数组拷贝的 srcPos: 从源数据的哪个位置开始拷贝 dest: 这个目的数组,,从源数组拷贝的数据拷贝到这个数组 destPos: 从源数组拷贝过来的数据存放在目的数组的开始位置 length: 从原来组拷贝的数组元素的个数

    leetcode算法题

    最接近原点的 K 个点难度中等85收藏分享切换为英文关注反馈我们有一个由平面上的点组成的列表 points。需要从中找出 K 个距离原点 (0, 0) 最近的点。(这里,平面上两点之间的距离是欧几里德距离。)你可以按任何顺序返回答案。除了点坐标的顺序之外,答案确保是唯一的。

    class Solution { public int[][] kClosest(int[][] points, int K) { int[][] arr = new int[K][2]; Arrays.sort(points,(int[] o1,int[] o2)->(o1[0]*o1[0]+o1[1]*o1[1]-o2[0]*o2[0]-o2[1]*o2[1])); System.arraycopy(points,0,arr,0,K); return arr; } }
    Processed: 0.010, SQL: 9