Skip to content

Commit

Permalink
Update 0347. 前 K 个高频元素.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed Sep 19, 2023
1 parent aa43916 commit 4ee898d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Solutions/0347. 前 K 个高频元素.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

## 题目大意

**描述**:给定一个整数数组 `nums` 和一个整数 `k`
**描述**:给定一个整数数组 $nums$ 和一个整数 $k$

**要求**:返回出现频率前 `k` 高的元素。可以按任意顺序返回答案。
**要求**:返回出现频率前 $k$ 高的元素。可以按任意顺序返回答案。

**说明**

- $1 \le nums.length \le 10^5$。
- $k$ 的取值范围是 $[1, 数组中不相同的元素的个数]$。
- $k$ 的取值范围是 $[1, \text{数组中不相同的元素的个数}]$。
- 题目数据保证答案唯一,换句话说,数组中前 $k$ 个高频元素的集合是唯一的。

**示例**
Expand Down Expand Up @@ -40,7 +40,7 @@
3. 使用二叉堆构建优先队列,优先级为元素频数。此时堆顶元素即为频数最高的元素。时间复杂度 $O(n)$,空间复杂度 $O(n)$。
4. 将堆顶元素加入到答案数组中,进行出队操作。时间复杂度 $O(log{n})$。
- 出队操作:交换堆顶元素与末尾元素,将末尾元素已移出堆。继续调整大顶堆。
5. 不断重复第 4 步,直到 `k` 次结束。调整 `k` 次的时间复杂度 $O(nlog{n})$。
5. 不断重复第 4 步,直到 $k$ 次结束。调整 $k$ 次的时间复杂度 $O(n \times \log n)$。

### 思路 1:代码

Expand Down Expand Up @@ -129,5 +129,5 @@ class Solution:

### 思路 1:复杂度分析

- **时间复杂度**:$O(n \times \log_2n)$。
- **时间复杂度**:$O(n \times \log n)$。
- **空间复杂度**:$O(n)$。

0 comments on commit 4ee898d

Please sign in to comment.