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