[Java/Python 3] Straight forward codes.
Q & A\nQ1: Why have you initialized index with -1 and not 0?\n\nA1: Make the code more general. e.g., If no point has the same x or y coordinate, then we can st
**Q & A**\nQ1: Why have you initialized index with `-1` and not `0`?\n\nA1: Make the code more general. e.g., If no point has the same `x` or `y` coordinate, then we can still detect it by the return value. Otherwise, if the return value is `0`, we would NOT know whether the point at index `0` is the solution or not.\n\n**End of Q & A**\n\n----\n\nExplanation by **@lionkingeatapple**\n\nBecause we want A point that shares the same `x`-coordinate or the same `y`-coordinate as your location, `dx * dy == 0` indicate either `dx` equals zero or `dy` equals zero, so we can make the product of `dx` and `dy` to be zero. `dx` and `dy` means the difference of `x`-coordinate and `y`-coordinate respectively. If the difference is zero, then they must be equal or shares the same `x/y`-coordinate.\n\nAlso, credit to **@KellyBundy** for improvement.\n\n```java\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int index = -1; \n        for (int i = 0, smallest = Integer.MAX_VALUE; i < points.length; ++i) {\n            int dx = x - points[i][0], dy = y - points[i][1];\n            if (dx * dy == 0 && Math.abs(dy + dx) < smallest) {\n                smallest = Math.abs(dx + dy);\n                index = i;\n            }\n        }\n        return index;\n    }\n```\n\n```python\n    def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n        index, smallest = -1, math.inf\n        for i, (r, c) in enumerate(points):\n            dx, dy = x - r, y - c\n            if dx * dy == 0 and abs(dx + dy) < smallest:\n                smallest = abs(dx + dy)\n                index = i\n        return index\n```
[]