Skip to content

Commit 05e4c2a

Browse files
committed
feat: 0347.Top-K-Frequent-Elements
1 parent 81b4806 commit 05e4c2a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Leetcode/0347.Top-K-Frequent-Elements/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ import (
154154

155155
// 方法一: 使用 PriorityQueue
156156
// 時間複雜 O(Nlog⁡k), 空間複雜 O(N)
157+
// 首先遍歷整個數組,並使用哈希表記錄每個數字出現的次數,並形成一個「出現次數數組」
158+
// 建立一個 PriortyQueue, 將「出現次數數組」丟進去
159+
// 在把 PriortyQueue pop的值丟到 result
157160
func TopKFrequent(nums []int, k int) []int {
158161
m := make(map[int]int)
159162
for i := 0; i < len(nums); i++ {

Leetcode/0347.Top-K-Frequent-Elements/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77

88
// 方法一: 使用 PriorityQueue
99
// 時間複雜 O(Nlog⁡k), 空間複雜 O(N)
10+
// 首先遍歷整個數組,並使用哈希表記錄每個數字出現的次數,並形成一個「出現次數數組」
11+
// 建立一個 PriortyQueue, 將「出現次數數組」丟進去
12+
// 在把 PriortyQueue pop的值丟到 result
1013
func TopKFrequent(nums []int, k int) []int {
1114
m := make(map[int]int)
1215
for i := 0; i < len(nums); i++ {

0 commit comments

Comments
 (0)