1
class Solution {
2
public double[] sampleStats(int[] count) {
3
double[] ans = new double[5];
4
ans[0] = -1;
5
ans[1] = -1;
6
int place = 0;
7
while (ans[0] == -1) {
8
if (count[place] > 0) ans[0] = place;
9
place++;
10
}
11
place = count.length - 1;
12
while (ans[1] == -1) {
13
if (count[place] > 0) ans[1] = place;
14
place--;
15
}
16
int countEl = count[0];
17
int max = count[0];
18
for (int i = 1; i < count.length; i++) {
19
countEl += count[i];
20
if (count[i] > max) {
21
max = count[i];
22
ans[4] = i;
23
}
24
}
25
for (int i = 0; i < count.length; i++) {
26
if (count[i] > 0) {
27
double tmp = count[i];
28
tmp /= countEl;
29
ans[2] += tmp * i;
30
}
31
}
32
place = 0;
33
int whereToStop = 0;
34
while (whereToStop < countEl / 2) {
35
whereToStop += count[place];
36
place++;
37
}
38
place--;
39
if (countEl % 2 == 1) {
40
if (whereToStop == countEl / 2) {
41
place++;
42
while (count[place] == 0) place++;
43
}
44

45
ans[3] = place;
46
} else {
47
double tmp = place;
48
if (whereToStop == countEl / 2) {
49
place++;
50
while (count[place] == 0) place++;
51
}
52
tmp += place;
53
ans[3] = tmp / 2;
54
}
55
return ans;
56
}
57
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0