[JAVA] || goto approach, simple and explained
Algorithm explained\nTo keep the runtime low we check for valid points and the closest one in a single run through (loop).\n\n\nclass Solution {\n    public int
**Algorithm explained**\nTo keep the runtime low we check for valid points and the closest one in a single run through (loop).\n\n```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n\n        int minDist=Integer.MAX_VALUE;   //the variable to keep track of the minimal distance so far\n        int currentDist=0;  //the current distance between our point and the current valid point from points[][]\n\t\tint index=-1;   //the index of the future valid point with minimal distance (-1 if there are no valid points)\n        \n        for(int i=0; i<points.length; i++){\n\t\t\tif(points[i][0]==x||points[i][1]==y){    //if either x or y-coordinate are the same the point is valid\n            \n         currentDist=Math.abs(x-points[i][0])+Math.abs(y-points[i][1]);   //calculate distance\n            \n            if(currentDist<minDist){minDist=currentDist;  index=i;}   //check if its lower than the previous low\n        }    \n            \n        }\n       //if we ran through the entire we mustve found the right point \n       return index; \n    }\n}\n```
['Java']