Find Nearest Point That Has the Same X or Y Coordinate
\n\n# Code\n\nclass Solution {\n    public static class Points implements Comparable<Points>{\n        int x,y,d,i;\n        public Points(int x,int y,int d,int
\n\n# Code\n```\nclass Solution {\n    public static class Points implements Comparable<Points>{\n        int x,y,d,i;\n        public Points(int x,int y,int d,int i){\n            this.x=x;\n            this.y=y;\n            this.d=d;\n            this.i=i;\n        }\n        public int compareTo(Points p2){\n            if(this.d==p2.d)\n            return this.i - p2.i;\n            return this.d-p2.d;\n        }\n    }\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        PriorityQueue<Points> pq=new PriorityQueue<>();\n        for(int i=0;i<points.length;i++){\n            if(points[i][0]!=x && points[i][1]!=y)\n            continue;\n            int d=Math.abs(x-points[i][0])+Math.abs(y-points[i][1]);\n            pq.add(new Points(points[i][0], points[i][1], d,i));\n        }\n        if(pq.isEmpty())\n        return -1;\n        return pq.remove().i;\n    }\n}\n```
['Array', 'Java']