OJ-Problems-Source/LeetCode/1619.cpp
2022-09-14 20:50:14 +08:00

15 lines
342 B
C++

class Solution {
public:
double trimMean(vector<int>& arr) {
int n = arr.size();
int toRemove = n / 20;
sort(arr.begin(), arr.end());
int sum = 0;
for (int i = toRemove; i < n - toRemove; i++) {
sum += arr[i];
}
return (double)sum / (n - toRemove - toRemove);
}
};