2465. Number of Distinct Averages
Easy
You are given a 0-indexed integer array nums
of even length.
As long as nums
is not empty, you must repetitively:
Find the minimum number in
nums
and remove it.Find the maximum number in
nums
and remove it.Calculate the average of the two removed numbers.
The average of two numbers a
and b
is (a + b) / 2
.
For example, the average of
2
and3
is(2 + 3) / 2 = 2.5
.
Return the number of distinct averages calculated using the above process.
Note that when there is a tie for a minimum or maximum number, any can be removed.
Example 1:
Example 2:
Constraints:
2 <= nums.length <= 100
nums.length
is even.0 <= nums[i] <= 100
解題
Runtime: 0 ms, faster than 100%
Memory Usage: 1.9 MB, less than 91.22%
Previous2461. Maximum Sum of Distinct Subarrays With Length KNext2477. Minimum Fuel Cost to Report to the Capital ⭐
Last updated