-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathStatistics from a Large Sample.java
62 lines (61 loc) · 1.49 KB
/
Statistics from a Large Sample.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Solution {
public double[] sampleStats(int[] count) {
double[]ans=new double[5];
ans[0]=-1;
ans[1]=-1;
int place=0;
while(ans[0]==-1){
if(count[place]>0)
ans[0]=place;
place++;
}
place=count.length-1;
while(ans[1]==-1){
if(count[place]>0)
ans[1]=place;
place--;
}
int countEl=count[0];
int max=count[0];
for(int i=1;i<count.length;i++){
countEl+=count[i];
if(count[i]>max){
max=count[i];
ans[4]=i;
}
}
for(int i=0;i<count.length;i++){
if(count[i]>0){
double tmp=count[i];
tmp/=countEl;
ans[2]+=tmp*i;
}
}
place=0;
int whereToStop=0;
while(whereToStop<countEl/2){
whereToStop+=count[place];
place++;
}
place--;
if(countEl%2==1){
if(whereToStop==countEl/2){
place++;
while(count[place]==0)
place++;
}
ans[3]=place;
}
else{
double tmp=place;
if(whereToStop==countEl/2){
place++;
while(count[place]==0)
place++;
}
tmp+=place;
ans[3]=tmp/2;
}
return ans;
}
}