Skip to content

Create 40 2022 0308 Heap 3nd.md #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2022
Merged

Create 40 2022 0308 Heap 3nd.md #33

merged 3 commits into from
Apr 28, 2022

Conversation

ytyubox
Copy link
Member

@ytyubox ytyubox commented Mar 5, 2022

LeetCode 讀書會第 40 次聚會 2022/03/08

leetcode 讀書會通知

  1. 項目: 第 40 次聚會
  2. 目的: 線上一起寫題目, 由有想法的人帶領, 先解題, 再看該題有趣的解法
  3. 時間: 03/08 (二) 20:00 ~ 21:00
  4. 地點: google meet 線上 (前 10 分鐘預備鏈接)
  5. 解題項目: Heap
  6. 共筆: GitHub https://github.com/programmingbookclub/Leetcode-club
  7. 備註:

這次會強調嘗試 Binary Heap 從無到有的實作,從 347 開始。

@louis222220
Copy link
Contributor

會議中的訊息:

Y.J. Lee下午8:01
yoyoyo
Y.J. Lee下午8:05
語音滿乾淨的
Y.J. Lee下午8:12
heap implementation 可能就 percolate up/down 要記得
Y.J. Lee下午8:18
檢查parent的時候就直接取 //2
檢查children的時候就看max or min heap, 把大的/小的換上去
Y.J. Lee下午8:24
放進heap以後就pop K次 拿出前K大的
Y.J. Lee下午8:25
O(N)+ K*log(N)
Y.J. Lee下午8:26
heappush放進去的時候
會保持heap property
數完每個數字幾次
放進heap的時候得用heappush
Y.J. Lee下午8:27
不然就數完每個東西直接heapify
Y.J. Lee下午8:29
heap 裡面也可以用 pair 存 (count, value/index)
Y.J. Lee下午8:31
可以煮咖啡了
Y.J. Lee下午8:32
python 內建是 minHeap 所以他才要倒轉 (-x)
Y.J. Lee下午8:34
反著數
Y.J. Lee下午8:46
他是利用max_count < N
先準備好N個bucket
數完整坨東西 依照每個東西出現幾次
放進相對應的bucket
放完再從Nth bucket往回拿K個 element
max_count <= N
Y.J. Lee下午8:49
假設 [1,1,1,2,2]
數完 放完 就變成 [[], [], [2], [1], [], []]
假如 [5,5,5,5,5]
數完 放完 就變成 [[], [], [], [], [], [5]]
對啊 大部分heap可以的sort都可以
XD
Y.J. Lee下午8:53
沒有要補充~
先撤 大家晚安~
郁勳下午9:02
掰掰

@ytyubox
Copy link
Member Author

ytyubox commented Mar 8, 2022

@louis222220 謝謝

Co-authored-by: Louis <louis222220@gmail.com>
@ytyubox ytyubox merged commit b48f64a into main Apr 28, 2022
@ytyubox ytyubox deleted the 40-2022-0308-Heap-3nd branch April 28, 2022 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants