GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/475_Heaters.java at master · shangaro/leetcode Expand file tree/ Copy path475_Heaters.javaMore file actions 17 lines (16 loc) · 727 Bytes / Copy path475_Heaters.javaFile metadata and controls17 lines (16 loc) · 727 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public class Solution { public int findRadius(int[] houses, int[] heaters) { Arrays.sort(heaters); int result = Integer.MIN_VALUE; for (int house : houses) { // Java binarySearch return - insertPoint - 1 if not found // This point is greater than value you want int index = Arrays.binarySearch(heaters, house); if (index < 0) index = -(index + 1); int dist1 = index - 1 >= 0 ? house - heaters[index - 1] : Integer.MAX_VALUE; int dist2 = index < heaters.length ? heaters[index] - house : Integer.MAX_VALUE; result = Math.max(result, Math.min(dist1, dist2)); } return result; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |