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 (
154154
155155// 方法一: 使用 PriorityQueue
156156// 時間複雜 O(Nlogk), 空間複雜 O(N)
157+ // 首先遍歷整個數組,並使用哈希表記錄每個數字出現的次數,並形成一個「出現次數數組」
158+ // 建立一個 PriortyQueue, 將「出現次數數組」丟進去
159+ // 在把 PriortyQueue pop的值丟到 result
157160func TopKFrequent (nums []int , k int ) []int {
158161 m := make (map [int ]int )
159162 for i := 0 ; i < len (nums); i++ {
Original file line number Diff line number Diff line change 77
88// 方法一: 使用 PriorityQueue
99// 時間複雜 O(Nlogk), 空間複雜 O(N)
10+ // 首先遍歷整個數組,並使用哈希表記錄每個數字出現的次數,並形成一個「出現次數數組」
11+ // 建立一個 PriortyQueue, 將「出現次數數組」丟進去
12+ // 在把 PriortyQueue pop的值丟到 result
1013func TopKFrequent (nums []int , k int ) []int {
1114 m := make (map [int ]int )
1215 for i := 0 ; i < len (nums ); i ++ {
You can’t perform that action at this time.
0 commit comments