File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed
Leetcode/0347.Top-K-Frequent-Elements Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,9 @@ import (
154
154
155
155
// 方法一: 使用 PriorityQueue
156
156
// 時間複雜 O(Nlogk), 空間複雜 O(N)
157
+ // 首先遍歷整個數組,並使用哈希表記錄每個數字出現的次數,並形成一個「出現次數數組」
158
+ // 建立一個 PriortyQueue, 將「出現次數數組」丟進去
159
+ // 在把 PriortyQueue pop的值丟到 result
157
160
func TopKFrequent (nums []int , k int ) []int {
158
161
m := make (map [int ]int )
159
162
for i := 0 ; i < len (nums); i++ {
Original file line number Diff line number Diff line change 7
7
8
8
// 方法一: 使用 PriorityQueue
9
9
// 時間複雜 O(Nlogk), 空間複雜 O(N)
10
+ // 首先遍歷整個數組,並使用哈希表記錄每個數字出現的次數,並形成一個「出現次數數組」
11
+ // 建立一個 PriortyQueue, 將「出現次數數組」丟進去
12
+ // 在把 PriortyQueue pop的值丟到 result
10
13
func TopKFrequent (nums []int , k int ) []int {
11
14
m := make (map [int ]int )
12
15
for i := 0 ; i < len (nums ); i ++ {
You can’t perform that action at this time.
0 commit comments