Java | easy to understand
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 ans=-1;\n        int temp=10001;\n        for(int i=0;i<points.length;i++)\n        {\n            if(points[i][0]==x||points[i][1]==y)\n            {\n                int val=Math.abs(points[i][0]-x)+Math.abs(points[i][1]-y);\n                if(val<temp){\n                    temp=val;\n                    ans=i;\n                }\n            }\n        }\n        return ans;\n\n    }\n}\n```
['Java']