class Solution {
public:
double trimMean(vector<int>& arr) {
int N = arr.size();
sort(arr.begin(),arr.end());
int K = int(N*0.05+0.5);
double sum = 0;
for(int i=0;i<N;i++){
if(i < K) continue;
sum += arr[i];
}
for(int i=0;i<N;i++){
if(i < K) sum -= arr[N-1-i];
else break;
}
return sum/(N-K*2);
}
};
No.249 - LeetCode1619. Mean of Array After Removing Some Elements
最新推荐文章于 2024-11-11 20:59:17 发布