OJ-Problems-Source/LeetCode/1619.cpp

15 lines
342 B
C++
Raw Normal View History

2022-09-14 20:50:14 +08:00
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);
}
};