File tree Expand file tree Collapse file tree 3 files changed +9
-0
lines changed
Leetcode/0347.Top-K-Frequent-Elements Expand file tree Collapse file tree 3 files changed +9
-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 ++ {
Original file line number Diff line number Diff line change @@ -109,6 +109,9 @@ https://kimi0230.github.io/LeetcodeGolang/
109109
110110
111111#### Heap & Priority Queue
112+
113+ Heap 總是能讓整棵樹當中最大或最小值維持在root節點上
114+
112115##### Heap 有幾個特色:
113116* 常見架構是像 binary tree 那樣
114117* 保持 balanced
You can’t perform that action at this time.
0 commit comments