Easy Solution in Java for Beginners
Intuition\n Describe your first thoughts on how to solve this problem. \nBruteforce\n\n# Approach\n Describe your approach to solving the problem. \nWe want A p
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBruteforce\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe 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# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int min = 10000;\n        int index = -1;\n        for(int i =0 ; i<points.length; i++){\n           int dx = x - points[i][0];\n           int dy = y - points[i][1];\n           if(dx*dy==0 && Math.abs(dx+dy)<min){\n               min = Math.abs(dx+dy);\n               index =i;\n           }\n        }\n        return index;\n    }\n}\n```
['Array', 'Java']