Simple java code 2 ms beats 99 % && 49 mb beats 84 %
\n# Complexity\n-\n\n# Code\n\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int ind=-1;\n        int min=10001;\n
\n# Complexity\n-\n![image.png](https://assets.leetcode.com/users/images/0f5264f6-e9c0-4f0d-8e25-de216df6ea7d_1705208030.8378751.png)\n# Code\n```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int ind=-1;\n        int min=10001;\n        for(int i=0;i<points.length;i++) {\n            if(points[i][0]==x||points[i][1]==y) {\n                int val=Math.abs(points[i][0]-x)+Math.abs(points[i][1]-y);\n                if(val<min){\n                    min=val;\n                    ind=i;\n                }\n            }\n        }\n        return ind;\n\n    }\n}\n```
['Java']