for (int i = 0; i < array.length; i++) {
double previous = i == 0 ? Double.POSITIVE_INFINITY : array[i - 1];
double next = i < array.length ? array[i + 1] : Double.POSITIVE_INFINITY;
int current = array[i];
if (current > previous || current > next)
continue;
localMax[++s] = current;
}