Explanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array). Possible sets of size 2 are {3,5},{3,2},{5,2}. Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5...
【leetcode】1338. Reduce Array Size to The Half 题目如下: Given an arrayarr. You can choose a set of integers and remove all the occurrences of these integers in the array. Returnthe minimum size of the setso that at least half of the integers of the array are removed. Example 1: In...
Explanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array). Possible sets of size 2 are {3,5},{3,2},{5,2}. Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5...
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 theminimum sizeof the set so thatat leasthalf of the integers o...
Returnthe minimum size of the setso that at least half of the integers of the array are removed. 样例: 限制: 个人思路: 先一个字典统计所有的字符出现的个数,然后按照从大到小的顺序进行排序,然后count--,当count * 2 <= len(arr)时结束,统计此时减去的数字的个数即可。
1338. Reduce Array Size to The Half 问题: 给出一个数组,求至少拿出几个元素,使得他们出现的次数之和,>=总元素个数的一半 Example 1: Input: arr = [3,3,3,3,5,5,5,2,2,7] Output: 2 Explanation: Choosing {3,7} will make thenewarray [5,5,5,2,2] which has size 5 (i.e equal ...