Medium
LeetCode 120: Triangle
·2 分鐘
LeetCode
Medium
Dynamic-Programming
LeetCode 120 解題筆記,依照原始 learning note 重新整理
LeetCode 2196: Create Binary Tree From Descriptions
·1 分鐘
LeetCode
Medium
Tree
Binary-Tree
Hash-Map
LeetCode 2196 解題筆記:用 dict 存節點一次連好,根是唯一不是任何人子節點的值
LeetCode 3660: Jump Game IX
·1 分鐘
LeetCode
Medium
Dynamic-Programming
Array
LeetCode 3660 解題筆記:在 i 和 i+1 之間切一刀,如果左邊的最大值 > 右邊的最小值,兩邊就能互相跳到,答案一樣;否則左邊的答案就是左邊的最大值
LeetCode 1878: Get Biggest Three Rhombus Sums in a Grid
·1 分鐘
LeetCode
Medium
Matrix
Enumeration
Heap
LeetCode 1878 解題筆記:枚舉每個頂點和大小,沿四條邊走一圈加總,取前三大的不同值
LeetCode 1727: Largest Submatrix With Rearrangements
·1 分鐘
LeetCode
Medium
Greedy
Sorting
Matrix
LeetCode 1727 解題筆記:每列算出往上連續 1 的高度,欄可以重排,所以把高度由大到小排序,第 j 高乘上 j + 1
LeetCode 3713: Longest Balanced Substring I
·1 分鐘
LeetCode
Medium
Hash-Table
String
Counting
Enumeration
LeetCode 3713 解題筆記:固定起點往右擴;「每種字元次數都一樣」等於「最大次數 × 種類數 = 長度」,每一步 O(1) 判斷
LeetCode 1833: Maximum Ice Cream Bars
·1 分鐘
LeetCode
Medium
Greedy
Sorting
Counting-Sort
LeetCode 1833 解題筆記:從最便宜的開始買;題目要求計數排序,值域只有 10^5,每個價格一次買 min(數量, 錢 // 價格) 個
LeetCode 307: Range Sum Query - Mutable
·2 分鐘
LeetCode
Medium
Segment-Tree
Binary-Indexed-Tree
Design
Array
LeetCode 307 解題筆記:單點更新加區間和,前綴和每次更新要 O(n);用線段樹或 Fenwick Tree,兩種操作都是 O(log n)
LeetCode 3961: Maximize Sum of Device Ratings
·1 分鐘
LeetCode
Medium
Greedy
Sorting
Matrix
LeetCode 3961 解題筆記:除了一台以外,每台把最小的單位捐給同一台;那台的評分變成全域最小值,挑第二小值最小的那台當接收者
LeetCode 3960: Frequency Balance Subarray
·1 分鐘
LeetCode
Medium
Hash-Table
Counting
Array
LeetCode 3960 解題筆記:n 只有 1000,固定左端點往右擴,同時維護「值 -> 次數」和「次數 -> 個數」;只有 f 和 2f 兩種次數就成立
LeetCode 3952: Maximum Total Value of Covered Indices
·1 分鐘
LeetCode
Medium
Dynamic-Programming
State-Machine
Greedy
String
LeetCode 3952 解題筆記:每個代幣只能往左移一格,狀態是「這格的代幣有沒有往左移」;往左移只有在左邊那格原本沒被蓋住時才有用
LeetCode 3951: Minimum Energy to Maintain Brightness
·1 分鐘
LeetCode
Medium
Array
Sorting
LeetCode 3951 解題筆記:一盞燈最多照亮 3 個位置,每個時間單位至少要 ceil(brightness / 3) 盞;合併區間算出需要的總時間再相乘