본문 바로가기
IT/알고리즘

26★] Leetcode 1491. Average Salary Excluding the Minimum and Maximum Salary

by 깻잎쌈 2020. 7. 5.
반응형
 

Average Salary Excluding the Minimum and Maximum Salary - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

1. 문제를 똑바로 이해하고

2. 반환값이 int인지 double인지 확인하고

class Solution {
public:
    double average(vector<int>& salary) {
        sort(salary.begin(), salary.end());
        double total = 0.0;
        for(int i = 1;i<salary.size()-1;i++)
            total +=salary[i];
        
        return total/(salary.size()-2);
    }
};

 

반응형

댓글