java
class Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int a =0 ,b =0;\n        var maxdis = Integer.MAX_VALUE;\n        in
class Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int a =0 ,b =0;\n        var maxdis = Integer.MAX_VALUE;\n        int ans = -1;\n        int sum =0;\n        for(int i=0; i< points.length; i++){\n            a = points[i][0];\n            b = points[i][1];\n            if(x==a || y == b){\n                sum = Math.abs(x - a) + Math.abs(y-b);\n                if(sum < maxdis){\n                    maxdis = sum;\n                    ans = i;\n                }\n            }\n            \n        }\n        \n        return ans;\n    }\n}
['Java']