Hash-Table
LeetCode 1410: HTML Entity Parser
·1 分鐘
LeetCode
Medium
Hash-Table
String
LeetCode 1410 解題筆記:由左到右在每個位置嘗試比對六個 entity,比對到就整段跳過;不能用連續的 replace
LeetCode 3606: Coupon Code Validator
·1 分鐘
LeetCode
Easy
Hash-Table
String
Sorting
LeetCode 3606 解題筆記:先過濾合法的優惠券,再用(類別順序, code)排序;字元範圍要包含 z、Z、9
Sliding Window 滑動視窗
·5 分鐘
演算法
Sliding-Window
Two-Pointers
Hash-Table
Monotonic-Queue
固定長度視窗、可變長度求最長 / 最短、數子陣列個數(最多 K 相減、至少 K 用 count += left)、單調佇列維護視窗最值
LeetCode 2094: Finding 3-Digit Even Numbers
·1 分鐘
LeetCode
Easy
Hash-Table
Enumeration
Array
LeetCode 2094 解題筆記:反過來枚舉 100 到 998 的偶數,檢查需要的每個數字次數夠不夠;Counter 相減只留正數
LeetCode 3545: Minimum Deletions for At Most K Distinct Characters
·1 分鐘
LeetCode
Easy
Greedy
Hash-Table
String
Sorting
Counting
LeetCode 3545 解題筆記:要減少種類就得整種刪掉,從出現次數最少的開始刪
LeetCode 952: Largest Component Size by Common Factor
·2 分鐘
LeetCode
Hard
Math
Number-Theory
Union-Find
Hash-Table
Array
LeetCode 952 解題筆記:有共同因數 ⇔ 有共同的質因數;把每個數分解質因數,同一個質因數的 index 用 Union-Find 合併,不用兩兩算 GCD
LeetCode 3541: Find Most Frequent Vowel and Consonant
·1 分鐘
LeetCode
Easy
Hash-Table
String
Counting
LeetCode 3541 解題筆記:數每個字元的次數,母音取最大、子音取最大再相加;沒有的那一類算 0
LeetCode 3518: Smallest Palindromic Rearrangement II
·2 分鐘
LeetCode
Hard
Math
Combinatorics
Counting
Hash-Table
String
LeetCode 3518 解題筆記:回文由左半邊決定,變成「多重集合的第 k 個排列」;逐位試每個字元,用排列數判斷第 k 個落在哪個分支,排列數可以 O(1) 更新
LeetCode 3487: Maximum Unique Subarray Sum After Deletion
·1 分鐘
LeetCode
Easy
Greedy
Hash-Table
Array
LeetCode 3487 解題筆記:可以任意刪除,所以等於挑不重複的值;非負的全拿,全是負數時只拿最大的一個
LeetCode 3121: Count the Number of Special Characters II
·1 分鐘
LeetCode
Medium
Hash-Table
String
LeetCode 3121 解題筆記:記錄每個字母小寫最後一次出現和大寫第一次出現的位置,小寫最後一次在大寫第一次之前才算
LeetCode 3120: Count the Number of Special Characters I
·1 分鐘
LeetCode
Easy
Hash-Table
String
LeetCode 3120 解題筆記:分別收集出現過的小寫和大寫字母,兩個集合的交集大小就是答案
LeetCode 1814: Count Nice Pairs in an Array
·1 分鐘
LeetCode
Medium
Array
Hash-Table
Math
Counting
LeetCode 1814 解題筆記:把條件移項成 nums[i] - rev(nums[i]) == nums[j] - rev(nums[j]),按這個值分組數 pair,記得取模