We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给你一个整数数组nums,请你将数组按照每个值的频率升序排序。如果有多个值的频率相同,请你按照数值本身将它们降序排序。
nums
请你返回排序后的数组。
输入:nums = [1,1,2,2,2,3] 输出:[3,1,1,2,2,2] 解释:'3' 频率为 1,'1' 频率为 2,'2' 频率为 3 。
输入:nums = [2,3,1,3,2] 输出:[1,3,3,2,2] 解释:'2' 和 '3' 频率都为 2 ,所以它们之间按照数值本身降序排序。
输入:nums = [-1,1,-6,4,5,-6,1,4,1] 输出:[5,-1,4,4,-6,-6,1,1,1]
来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/sort-array-by-increasing-frequency 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered:
class Solution { /** * @param Integer[] $nums * @return Integer[] */ function frequencySort($nums) { $count_by_num = array_count_values($nums); usort($nums, function ($one, $two) use ($count_by_num) { if ($count_by_num[$one] === $count_by_num[$two]) { return $two <=> $one; } return $count_by_num[$one] <=> $count_by_num[$two]; }); return $nums; } }
Sorry, something went wrong.
No branches or pull requests
给你一个整数数组
nums
,请你将数组按照每个值的频率升序排序。如果有多个值的频率相同,请你按照数值本身将它们降序排序。请你返回排序后的数组。
示例 1:
示例 2:
示例 3:
提示:
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/sort-array-by-increasing-frequency
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered: