Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 663 Bytes

Question_1491.md

File metadata and controls

27 lines (22 loc) · 663 Bytes

LeetCode Records - Question 1491 Average Salary Excluding the Minimum and Maximum Salary

Attempt 1: Record the sum, the count, the min, and the max

class Solution {
    public double average(int[] salary) {
        double sum = 0;
        int count = 0;
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;

        for (int num : salary) {
            sum += num;
            count++;

            min = Math.min(min, num);
            max = Math.max(max, num);
        }

        return (sum - max - min) / (count - 2);
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.45 MB (Beats: 20.44%)