Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

1491. Average Salary Excluding the Minimum and Maximum Salary leetcode solution in c++

class Solution {
public:
    double average(vector<int>& salary) {
        double res;
        int n=salary.size(),sum=0;
        sort(salary.begin(),salary.end());
        for(int i=0;i<salary.size();i++)
        {
            sum+=salary[i];
        }
        res = sum - (salary[0] + salary[n-1]);
        res/=(n-2);
        return res;
    }
};
Source by codejudge.blogspot.com #
 
PREVIOUS NEXT
Tagged: #Average #Salary #Excluding #Minimum #Maximum #Salary #leetcode #solution
ADD COMMENT
Topic
Name
1+2 =