Two-Pointers
LeetCode 1498: Number of Subsequences That Satisfy the Given Sum Condition
·2 分鐘
LeetCode
Medium
Two-Pointers
Sorting
Binary-Search
Array
LeetCode 1498 解題筆記:子序列只看最小值和最大值,排序後順序無關;固定最小值 nums[left],中間的元素任意選,共 2^(right - left) 種
LeetCode 1712: Ways to Split Array Into Three Subarrays
·2 分鐘
LeetCode
Medium
Binary-Search
Prefix-Sum
Two-Pointers
LeetCode 1712 解題筆記:固定第一刀,第二刀的合法範圍用兩次 bisect 或兩個單調指針找出來
LeetCode 825: Friends Of Appropriate Ages
·2 分鐘
LeetCode
Medium
Two-Pointers
Sorting
Binary-Search
Array
LeetCode 825 解題筆記:排序後,每個人能送出邀請的對象是年齡落在 (0.5 × age + 7, age] 的一段區間,用兩個同向指針維護區間再扣掉自己
LeetCode 2200: Find All K-Distant Indices in an Array
·1 分鐘
LeetCode
Easy
Two-Pointers
Array
LeetCode 2200 解題筆記:每個 key 往左右各延伸 k 格,用一個指針記住已經輸出到哪裡,避免重疊的區間重複輸出
LeetCode 3794: Reverse String Prefix
·1 分鐘
LeetCode
Easy
Two-Pointers
String
LeetCode 3794 解題筆記:切片一行解決;手寫雙指針時要先把字串轉成 list
LeetCode 3750: Minimum Number of Flips to Reverse Binary String
·1 分鐘
LeetCode
Easy
Two-Pointers
Bit-Manipulation
String
LeetCode 3750 解題筆記:把二進位字串跟它的反轉逐位比較,不同的位數就是答案
LeetCode 2300: Successful Pairs of Spells and Potions
·1 分鐘
LeetCode
Medium
Binary-Search
Sorting
Two-Pointers
LeetCode 2300 解題筆記:藥水排序,每個咒語用 bisect 找門檻,門檻用整數 ceil 避免浮點誤差
LeetCode 3649: Number of Perfect Pairs
·1 分鐘
LeetCode
Medium
Two-Pointers
Math
Sorting
Array
LeetCode 3649 解題筆記:把條件化簡成「較大的絕對值 <= 2 × 較小的絕對值」,排序絕對值後用雙指針計數
LeetCode 3643: Flip Square Submatrix Vertically
·1 分鐘
LeetCode
Easy
Two-Pointers
Matrix
LeetCode 3643 解題筆記:只翻轉子矩陣的上下列,第 x + i 列和第 x + k - 1 - i 列的那一段互換
LeetCode 3439: Reschedule Meetings for Maximum Free Time (Sliding Window)
·2 分鐘
LeetCode
Daily
Medium
Array
Sliding-Window
Two-Pointers
Intervals
LeetCode 解題紀錄
LeetCode 30: Substring with Concatenation of All Words
·2 分鐘
LeetCode
Daily
Hard
String
Sliding-Window
Two-Pointers
Hash-Map
Brute-Force
Frequency-Counting
三種作法:暴力、計數優化、偏移量滑動視窗。
LeetCode 209: Minimum Size Subarray Sum
·1 分鐘
LeetCode
Daily
Medium
Array
Sliding-Window
Two-Pointers
Prefix-Sum
Binary-Search
滑動視窗與雙指針,最小化子陣列長度(總和 ≥ target)。