Skip to content

Commit

Permalink
feat: 1619. Mean of Array After Removing Some Elements (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: ashing <axingfly@gmail.com>
  • Loading branch information
ronething authored Feb 3, 2024
1 parent 2dc7139 commit 893cd28
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions leetcode/1619/1619. Mean of Array After Removing Some Elements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package _619

import "sort"

func trimMean(arr []int) float64 {
sort.Ints(arr)
n := len(arr)
sum := 0
for _, x := range arr[n/20 : 19*n/20] {
sum += x
}
return float64(sum*10) / float64(n*9)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package _619

import (
"testing"
)

func Test_trimMean(t *testing.T) {
type args struct {
arr []int
}
tests := []struct {
name string
args args
want float64
}{
{
name: "one",
args: args{
[]int{1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3},
},
want: 2.00000,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := trimMean(tt.args.arr); got != tt.want {
t.Errorf("trimMean() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 893cd28

Please sign in to comment.