[코테 풀이] Average Salary Excluding the Minimum and Maximum Salary

시내·2024년 6월 8일

Q_1491) Average Salary Excluding the Minimum and Maximum Salary

출처 : https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/?envType=study-plan-v2&envId=programming-skills

You are given an array of unique integers salary where salary[i] is the salary of the ith employee.

Return the average salary of employees excluding the minimum and maximum salary. Answers within 10^-5 of the actual answer will be accepted.

class Solution {
    public double average(int[] salary) {
         ArrayList<Integer> sal = new ArrayList<>();
        for (int i : salary) sal.add(i);
        Collections.sort(sal);
        int sum = 0;
        System.out.println(sal);
        for (int j = 1; j < sal.size() - 1; j++) {
            sum += sal.get(j);
        }
        return sum / (double) (sal.size() - 2);
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글