java.lang.Object
g2401_2500.s2465_number_of_distinct_averages.Solution

public class Solution extends Object
2465 - Number of Distinct Averages.<p>Easy</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length.</p> <p>As long as <code>nums</code> is <strong>not</strong> empty, you must repetitively:</p> <ul> <li>Find the minimum number in <code>nums</code> and remove it.</li> <li>Find the maximum number in <code>nums</code> and remove it.</li> <li>Calculate the average of the two removed numbers.</li> </ul> <p>The <strong>average</strong> of two numbers <code>a</code> and <code>b</code> is <code>(a + b) / 2</code>.</p> <ul> <li>For example, the average of <code>2</code> and <code>3</code> is <code>(2 + 3) / 2 = 2.5</code>.</li> </ul> <p>Return <em>the number of <strong>distinct</strong> averages calculated using the above process</em>.</p> <p><strong>Note</strong> that when there is a tie for a minimum or maximum number, any can be removed.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [4,1,4,0,3,5]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <ol> <li> <p>Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].</p> </li> <li> <p>Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].</p> </li> <li> <p>Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.</p> </li> </ol> <p>Since there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,100]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong></p> <p>There is only one average to be calculated after removing 1 and 100, so we return 1.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 100</code></li> <li><code>nums.length</code> is even.</li> <li><code>0 <= nums[i] <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • distinctAverages

      public int distinctAverages(int[] nums)