-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1093_StatisiticsFromALargeSample.py
56 lines (51 loc) · 1.63 KB
/
1093_StatisiticsFromALargeSample.py
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
class Solution:
def sampleStats(self, count: List[int]) -> List[float]:
output = []
# minimum
for i in range(len(count)):
if count[i] > 0:
output.append(float(i))
break
# maximum
for m in range(len(count)-1,-1,-1):
if count[m] > 0:
output.append(float(m))
break
#mean
summy = 0
lenny = 0
for m in range(len(count)):
if count[m] > 0:
summy += m * count[m]
lenny += count[m]
output.append(float(summy/lenny))
#median
counted = 0
median = 0
if lenny % 2 == 1:
for m in range(len(count)):
if count[m] > 0:
counted += count[m]
if lenny//2 < counted:
median = float(m)
break
output.append(float(m))
else:
midl, midr = 0,0
for m in range(len(count)):
if count[m] > 0:
counted += count[m]
if lenny//2 < counted:
midr = m
break
counted = 0
for m in range(len(count)):
if count[m] > 0:
counted += count[m]
if (lenny//2)-1 < counted:
midl = m
break
output.append(float((midl+midr)/2))
#mode
output.append(float(count.index(max(count))))
return output