easy c++ approach
\n# Complexity\n- Time complexity:\no(n)\n\n\n\n# Code\n\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n   
\n# Complexity\n- Time complexity:\no(n)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int mindis=INT_MAX;\n        int ans=-1;\n        for(int i=0;i<points.size();i++){\n            if(points[i][0]==x || points[i][1]==y){\n                int dis=abs(x-points[i][0])+abs(y-points[i][1]);\n                if(dis<mindis){\n                    mindis=dis;\n                    ans=i;\n                   \n                }\n              \n            }\n        }\n        return ans;\n    }\n};\n```
['C++']