C++ Solution for beginners
\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int ans=-1;\n        int dis;\n        int min_dis=
```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int ans=-1;\n        int dis;\n        int min_dis=INT_MAX;\n        for(int i=0;i<points.size();i++)\n        {\n            if(points[i][0]==x or points[i][1]==y)\n            {\n                dis=abs(x-points[i][0])+abs(y-points[i][1]);\n                if(dis<min_dis)\n                {\n                    min_dis=dis;\n                    ans=i;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']