1491. Average Salary Excluding the Minimum and Maximum Salary

1491. Average Salary Excluding the Minimum and Maximum Salary

class Solution {
    public double average(int[] salary) {
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        double sum = 0;
        for(int i = 0; i < salary.length; i++){
                sum+=salary[i];
                min = Integer.min(min,salary[i]);
                max = Integer.max(max, salary[i]);
        }
        return (sum-min-max)/(salary.length - 2);
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s