题目 https://leetcode.com/problems/reduce-array-size-to-the-half/ 题解 先统计每个数字出现次数,然后给出现次数排序。出现次数多者,先被选中。 比较简单,官方题解也是 O(nlogn) 的时间复杂度。不知道为啥是个 medium 题。 class Solution { public int minSetSize(int
题目地址: https://leetcode.com/problems/reduce-array-size-to-the-half/ 给定一个长 n n n的数组,可以选择若干个不同数字清除(每次会把该数在数组中的所有出现都清除),问至少选多少个数字清
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: Input: arr = [3,3,3,3,5,5,
题目: 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. 样例: 限制: 个人思路: 先一个