Prefix-Sum
Binary Search 二分搜尋
·5 分鐘
演算法
Binary-Search
Prefix-Sum
Two-Pointers
lower / upper bound、對答案二分、第 k 小、整數開根號,以及兩種區間寫法不能混用
LeetCode 4051: Count Subarrays with Distant Sums
·4 分鐘
LeetCode
Hard
Merge-Sort
Prefix-Sum
Binary-Indexed-Tree
Biweekly-Contest
LeetCode 4051 解題筆記:前綴和 + 補集 + 區間計數,以及 k = 0 的邊界
LeetCode 2218: Maximum Value of K Coins From Piles
·1 分鐘
LeetCode
Hard
Dynamic-Programming
Knapsack
Prefix-Sum
Array
LeetCode 2218 解題筆記:每一堆只能從上面拿,拿 x 個的價值是前綴和;分組背包,dp[j] = 前幾堆總共拿 j 個的最大價值,每一堆枚舉拿幾個
LeetCode 1292: Maximum Side Length of a Square with Sum Less than or Equal to Threshold
·2 分鐘
LeetCode
Medium
Binary-Search
Prefix-Sum
Matrix
LeetCode 1292 解題筆記:二維前綴和加上對邊長二分;兩種二分寫法不能混用
LeetCode 410: Split Array Largest Sum
·1 分鐘
LeetCode
Hard
Dynamic-Programming
Binary-Search
Greedy
Prefix-Sum
Array
LeetCode 410 解題筆記:對答案二分搜尋;給定上限 mid,貪心地能塞就塞,數出最少要切幾段,段數 <= k 就表示 mid 可行
LeetCode 327: Count of Range Sum
·2 分鐘
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Prefix-Sum
Binary-Indexed-Tree
LeetCode 327 解題筆記:前綴和 + merge sort 計數,兩個指針卡出區間;重打十幾次的練習紀錄
LeetCode 3548: Equal Sum Grid Partition II
·2 分鐘
LeetCode
Hard
Prefix-Sum
Hash-Table
Matrix
Enumeration
LeetCode 3548 解題筆記:枚舉橫切(直切用轉置),兩邊差值要等於較大那邊某一格的值;那一邊只有一列或一欄時只能去掉兩端,否則任何一格都可以
LeetCode 2382: Maximum Segment Sum After Removals
·1 分鐘
LeetCode
Hard
Union-Find
Prefix-Sum
Ordered-Set
Array
LeetCode 2382 解題筆記:倒著做,把刪除變成加回去;Union-Find 的根記區段總和,最大值只會變大
LeetCode 3919: Minimum Cost to Move Between Indices
·1 分鐘
LeetCode
Medium
Greedy
Prefix-Sum
Array
LeetCode 3919 解題筆記:一步一步走,每一步成本是 1(下一格是 closest)或差值;直接跳不會更便宜,用前綴和回答查詢
LeetCode 3904: Smallest Stable Index II
·1 分鐘
LeetCode
Medium
Prefix-Sum
Array
LeetCode 3904 解題筆記:前綴最大值減後綴最小值 <= k 的第一個 index;後綴最小值先從右往左建好
LeetCode 3903: Smallest Stable Index I
·1 分鐘
LeetCode
Easy
Prefix-Sum
Array
LeetCode 3903 解題筆記:前綴最大值減後綴最小值 <= k 的第一個 index;後綴最小值先從右往左建好
LeetCode 3900: Longest Balanced Substring After One Swap
·2 分鐘
LeetCode
Medium
Prefix-Sum
Hash-Table
String
LeetCode 3900 解題筆記:前綴差值相同就平衡;差 2 的子字串只要外面有可以換進來的字元也行,每個差值記最早的兩個位置就夠