-
1779. Find Nearest Point That Has the Same X or Y Coordinate javaLeetCode_Study_Plan/Programming Skills 2022. 9. 19. 22:04
Find Nearest Point That Has the Same X or Y Coordinate - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution { public int nearestValidPoint(int x, int y, int[][] points) { int index = -1; int distance = Integer.MAX_VALUE; for (int i = 0; i < points.length; i++) { if (x == points[i][0] || y == points[i][1]) { int current_dis = Math.abs(x - points[i][0]) + Math.abs(y - points[i][1]); if (current_dis < distance) { distance = current_dis; index = i; } } } return index; } }
'LeetCode_Study_Plan > Programming Skills' 카테고리의 다른 글
1502. Can Make Arithmetic Progression From Sequence java (0) 2022.09.19 1822. Sign of the Product of an Array java (0) 2022.09.19 976. Largest Perimeter Triangle java (0) 2022.09.19 1281. Subtract the Product and Sum of Digits of an Integer java (0) 2022.09.19 191. Number of 1 Bits java (1) 2022.09.19