Simple JAVA Solution for beginners. 2ms. Beats 67.96%.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int manhattanDistance;\n        int smallestManhattanDistance = Integer.MAX_VALUE;\n        int smallestManhattanDistanceIndex = -1;\n        for(int i = 0; i < points.length; i++) {\n            if(x == points[i][0] || y == points[i][1]) {\n                manhattanDistance = Math.abs(x - points[i][0]) + Math.abs(y - points[i][1]);\n                if(manhattanDistance < smallestManhattanDistance) {\n                    smallestManhattanDistance = manhattanDistance;\n                    smallestManhattanDistanceIndex = i;\n                }\n            }\n        }\n        return smallestManhattanDistanceIndex;\n    }\n}\n```
['Array', 'Java']