Skip to content

Commit

Permalink
1619. Mean of Array After Removing Some Elements.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
keineahnung2345 authored Oct 25, 2020
1 parent 2efe407 commit 906416f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 1619. Mean of Array After Removing Some Elements.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//Runtime: 28 ms, faster than 11.60% of C++ online submissions for Mean of Array After Removing Some Elements.
//Memory Usage: 10 MB, less than 99.83% of C++ online submissions for Mean of Array After Removing Some Elements.
class Solution {
public:
double trimMean(vector<int>& arr) {
int n = arr.size();

int rem = n*5.0/100;

sort(arr.begin(), arr.end());

return (double)accumulate(arr.begin()+rem, arr.end()-rem, 0)/(n-2*rem);
}
};

0 comments on commit 906416f

Please sign in to comment.