Elegant Python, C++
Python\n\nclass Solution:\n    def nearestValidPoint(self, x, y, points):\n        best  = 100000\n        where = -1\n        \n        for i,ab in enumerate(p
**Python**\n```\nclass Solution:\n    def nearestValidPoint(self, x, y, points):\n        best  = 100000\n        where = -1\n        \n        for i,ab in enumerate(points):\n            a,b = ab\n            if a==x or b==y:\n                d = abs(x-a) + abs(y-b)\n                if d<best:\n                    best  = d\n                    where = i\n        return where\n```\n\n**C++**\n```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        \n        int     best   =  100000;\n        int     where  =  -1;\n        size_t  L      =  points.size();\n        int     a,b,d;\n\t\t\n        for (size_t i = 0; i<L; i++){\n            a = points[i][0];\n            b = points[i][1];\n            if (a==x | b==y){\n                d = abs(x-a) + abs(y-b);\n                if (d<best){\n                    best = d;\n                    where = i;\n                }\n            }\n        }\n        return where;\n    }\n};\n```
['C', 'Python', 'Python3']