其他分享
首页 > 其他分享> > 1491. Average Salary Excluding the Minimum and Maximum Salary

1491. Average Salary Excluding the Minimum and Maximum Salary

作者:互联网

!!!题目地址!!!

class Solution {
public:
    double average(vector<int>& salary) {
        int maxNum = salary[0];
        int minNum = salary[0];
        int total = 0;
        for (int i = 0; i < salary.size(); i++){
            if(salary[i] > maxNum)
            {
                maxNum = salary[i];
            }else if(salary[i] < minNum)
            {
                minNum = salary[i];
            }
            total += salary[i];
        }
        return (double)(total-maxNum-minNum)/(salary.size() - 2);
    }
};

标签:Salary,salary,maxNum,Excluding,int,Average,minNum,total,size
来源: https://www.cnblogs.com/realms/p/16282967.html