Java Solution 1ms 100% faster
\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n         int [] solution = {0,Integer.MAX_VALUE};\n        int index = 0;\
```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n         int [] solution = {0,Integer.MAX_VALUE};\n        int index = 0;\n        for(int[] point:points){\n            if(x == point[0] || y == point[1]){\n                int sum = Math.abs(x - point[0]) + Math.abs(y - point[1]);\n                if (sum < solution[1]){\n                    solution[0] = index;\n                    solution[1] = sum;\n                }\n            }\n            index++;\n        }\n        return  (solution[1] == Integer.MAX_VALUE) ? -1 : solution[0];\n    }\n}\n```
['Array']