Count Elements With Strictly Smaller and Greater Elements

给一个数组, 问这个数组有多少个数字是至少有一个数字严格比它大还有一个严格比它小的.

class Solution {
    public int countElements(int[] nums) {
        int nMax = 0;
        int max = Integer.MIN_VALUE;
        int nMin = 0;
        int min = Integer.MAX_VALUE;
        for(int n : nums){
            max = Math.max(max, n);
            min = Math.min(min, n);
        }
        for(int n : nums){
            if(n == max)
                nMax++;
            if(n == min)
                nMin++;
        }
        if(nMax == nums.length)
            return 0;
        return nums.length - nMax - nMin;
    }
}