Mean of Array After Removing Some Elements LeetCode solution in C++

1
class Solution {
2
public:
3
double trimMean(vector<int> &arr) {
4
auto first = arr.begin() + arr.size() / 20;
5
auto second = arr.end() - arr.size() / 20;
6
nth_element(arr.begin(), first, arr.end());
7
nth_element(first, second, arr.end());
8
return accumulate(first, second, 0.0) / distance(first, second);
9
}
10
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0