1342. Reduce Array Size to The Half
https://leetcode.com/problems/reduce-array-size-to-the-half/
Given an array arr
. You can choose a set of integers and remove all the occurrences of these integers in the array.
Return the minimum size of the set so that at least half of the integers of the array are removed.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Constraints:
1 <= arr.length <= 10^5
arr.length
is even.1 <= arr[i] <= 10^5
选定元素值可去除数组中所有等值的元素,问最少可选几个元素能让数组长度降到一半或以下。统计元素出现的频率,从频率最高开始删直到满足条件。因此把频率看作bucket,把对应频率的元素个数放到bucket中。
Previous1296. Divide Array in Sets of K Consecutive NumbersNext1353. Maximum Number of Events That Can Be Attended
Last updated
Was this helpful?