File tree 2 files changed +18
-17
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder 2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change 3
3
import java .util .Arrays ;
4
4
5
5
/**
6
- * 475. _475
6
+ * 475.
7
7
*
8
8
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.
9
9
29
29
*/
30
30
public class _475 {
31
31
32
- //credit: https://discuss.leetcode.com/topic/71460/short-and-clean-java-binary-search-solution
33
- public static int findRadius (int [] houses , int [] heaters ) {
34
- Arrays .sort (heaters );
35
- int radius = Integer .MIN_VALUE ;
36
- for (int house : houses ) {
37
- int index = Arrays .binarySearch (heaters , house );
38
- if (index < 0 ) {
39
- index = ~index ;
32
+ public static class Solution1 {
33
+ //credit: https://discuss.leetcode.com/topic/71460/short-and-clean-java-binary-search-solution
34
+ public int findRadius (int [] houses , int [] heaters ) {
35
+ Arrays .sort (heaters );
36
+ int radius = Integer .MIN_VALUE ;
37
+ for (int house : houses ) {
38
+ int index = Arrays .binarySearch (heaters , house );
39
+ if (index < 0 ) {
40
+ index = ~index ;
41
+ }
42
+ int distance1 = index - 1 >= 0 ? house - heaters [index - 1 ] : Integer .MAX_VALUE ;
43
+ int distance2 = index < heaters .length ? heaters [index ] - house : Integer .MAX_VALUE ;
44
+
45
+ radius = Math .max (radius , Math .min (distance1 , distance2 ));
40
46
}
41
- int distance1 = index - 1 >= 0 ? house - heaters [index - 1 ] : Integer .MAX_VALUE ;
42
- int distance2 = index < heaters .length ? heaters [index ] - house : Integer .MAX_VALUE ;
43
-
44
- radius = Math .max (radius , Math .min (distance1 , distance2 ));
47
+ return radius ;
45
48
}
46
- return radius ;
47
49
}
48
-
49
50
}
Original file line number Diff line number Diff line change 10
10
* Created by fishercoder on 4/23/17.
11
11
*/
12
12
public class _475Test {
13
- private static _475 test ;
13
+ private static _475 . Solution1 test ;
14
14
private static int expected ;
15
15
private static int actual ;
16
16
private static int [] houses ;
17
17
private static int [] heaters ;
18
18
19
19
@ BeforeClass
20
20
public static void setup () {
21
- test = new _475 ();
21
+ test = new _475 . Solution1 ();
22
22
}
23
23
24
24
@ Test
You can’t perform that action at this time.
0 commit comments