package leetcode;

/**
 * https://leetcode.com/problems/k-closest-points-to-origin/
 */
public class Problem973 {
    public int[][] kClosest(int[][] points, int K) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem973 prob = new Problem973();
    }
}

@@ -12,16 +12,123 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -279,132 +279,1574 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem973 prob = new Problem973();
+List%3CPointDistance%3E list = new ArrayList%3C%3E();%0A        for (int%5B%5D point : points) %7B%0A            double distance = Math.sqrt((Math.abs(point%5B0%5D) * Math.abs(point%5B0%5D)) +%0A                (Math.abs(point%5B1%5D) * Math.abs(point%5B1%5D)));%0A            list.add(new PointDistance(point, distance));%0A        %7D%0A        Collections.sort(list, (a, b) -%3E %7B%0A            if (a.distance %3C b.distance) %7B%0A                return -1;%0A            %7D else if (a.distance == b.distance) %7B%0A                return 0;%0A            %7D%0A            return 1;%0A        %7D);%0A        int%5B%5D%5B%5D answer = new int%5BK%5D%5B%5D;%0A        for (int i = 0; i %3C K; i++) %7B%0A            answer%5Bi%5D = list.get(i).point;%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static class PointDistance %7B%0A        private final int%5B%5D point;%0A        private final double distance;%0A%0A        public PointDistance(int%5B%5D point, double distance) %7B%0A            this.point = point;%0A            this.distance = distance;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return Arrays.toString(point) + %22 --%3E %22 + distance;%0A        %7D%0A    %7D%0A%0A    private static void print(int%5B%5D%5B%5D answer) %7B%0A        for (int%5B%5D i : answer) %7B%0A            System.out.print(Arrays.toString(i) + %22 %22);%0A        %7D%0A        System.out.println();%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem973 prob = new Problem973();%0A        print(prob.kClosest(new int%5B%5D%5B%5D%7B%0A            %7B1, 3%7D, %7B-2, 2%7D%0A        %7D, 1)); // %5B%5B-2,2%5D%5D%0A        print(prob.kClosest(new int%5B%5D%5B%5D%7B%0A            %7B3, 3%7D, %7B5, -1%7D, %7B-2, 4%7D%0A        %7D, 2)); // %5B%5B3,3%5D,%5B-2,4%5D%5D
 %0A   

Update problem 973