1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/按照频率将数组升序排序 [sort-array-by-increasing-frequency].html
2022-03-29 12:43:11 +08:00

34 lines
984 B
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>nums</code> ,请你将数组按照每个值的频率 <strong>升序</strong> 排序。如果有多个值的频率相同,请你按照数值本身将它们 <strong>降序</strong> 排序。 </p>
<p>请你返回排序后的数组。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [1,1,2,2,2,3]
<b>输出:</b>[3,1,1,2,2,2]
<b>解释:</b>'3' 频率为 1'1' 频率为 2'2' 频率为 3 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [2,3,1,3,2]
<b>输出:</b>[1,3,3,2,2]
<b>解释:</b>'2' 和 '3' 频率都为 2 ,所以它们之间按照数值本身降序排序。
</pre>
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>nums = [-1,1,-6,4,5,-6,1,4,1]
<b>输出:</b>[5,-1,4,4,-6,-6,1,1,1]</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
</ul>