Leetcode Note: Go - Mean of Array After Removing Some Elemebnts
Mean of Array After Removing Some Elements - LeetCode
https://leetcode.com/problems/mean-of-array-after-removing-some-elements/
- Go 言語で取り組んだメモ
回答
Golang O(n log(n) + (len(arr) * 0.90)), O(1) solution with explanation - Mean of Array After Removing Some Elements - LeetCode
https://leetcode.com/problems/mean-of-array-after-removing-some-elements/solutions/1296446/golang-o-n-log-n-len-arr-0-90-o-1-solution-with-explanation/
func trimMean(arr []int) float64 {
sort.Ints(arr)
sum := 0
for i := len(arr) / 20; i < len(arr) - (len(arr) / 20); i++ {
sum += arr[i]
}
return float64(sum) / float64(len(arr) - (len(arr) / 20) * 2)
}