-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1619. Mean of Array After Removing Some Elements.cpp
- Loading branch information
1 parent
2efe407
commit 906416f
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |