Easy Solution Beats 100%
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 m=Integer.MAX_VALUE;\n        for(int i=0;i<points.length;i++){\n            if(points[i][0]==x || points[i][1]==y){\n                int c=Math.min(points[i][0] , points[i][1]);\n                if(x==points[i][0]){\n                    if(m>Math.abs(points[i][1]-y)) {m=Math.abs(points[i][1]-y);\n                    ans=i;}\n                }\n                else{\n                    if(m>Math.abs(points[i][0]-x)) {m=Math.abs(points[i][0]-x);\n                    ans=i;}\n                }\n\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']