1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Java code below
import java.math.*;
class Solution {
static double closestToZero(double[] ts) {
if (ts.length == 0) {
return 0;
}
double closestToZero = ts[0];
double absClosest = Math.abs(closestToZero);
for (int i = 0; i < ts.length; ++i) {
double absValue = Math.abs(ts[i]);
if (absValue < absClosest || absValue == absClosest && ts[i] > 0) {
closestToZero = ts[i];
absClosest = absValue;
}
}
return closestToZero;
}
}
Press desired key combination and then press ENTER.
Skip pauses
03:53/03:53