Leetcode Note: Go - Average Salary Excluding the Minimum and Maximum Salary

Average Salary Excluding the Minimum and Maximum Salary - LeetCode
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/

  • Go 言語で取り組んだメモ

回答

Go ⭐ - Average Salary Excluding the Minimum and Maximum Salary - LeetCode
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/solutions/2323863/go/

func average(salary []int) float64 {
	var maxNum, minNum = salary[0], salary[0]
	var sumArr int

	for _, val := range salary {
		sumArr += val

		if val > maxNum {
			maxNum = val
		}

		if val < minNum {
			minNum = val
		}
	}

	return float64(sumArr-minNum-maxNum) / float64(len(salary)-2)
}