package com.fishercoder.solutions;

import java.util.PriorityQueue;

public class _973 {

    public static class Solution1 {
        public int[][] kClosest(int[][] points, int K) {
            int[][] ans = new int[K][2];

            PriorityQueue<int[]> pq = new PriorityQueue<>((o1, o2) -> {
                double dist1 = getDistance(o1);
                double dist2 = getDistance(o2);

                if (dist1 > dist2) {
                    return 1;
                } else if (dist1 < dist2) {
                    return -1;
                } else {
                    return 0;
                }
            });

            for (int[] point : points) {
                pq.add(point);
            }

            for (int i = 0; i < K; i++) {
                ans[i] = pq.poll();
            }

            return ans;
        }

        private double getDistance(int[] point) {
            return Math.sqrt(Math.pow(point[0], 2) + Math.pow(point[1], 2));
        }
    }
}

@@ -171,17 +171,17 @@
 ts, int 
-K
+k
 ) %7B%0A    
@@ -210,17 +210,17 @@
 new int%5B
-K
+k
 %5D%5B2%5D;%0A%0A 
@@ -742,9 +742,9 @@
 i %3C 
-K
+k
 ; i+

refactor 973