String
LeetCode 2730: Find the Longest Semi-Repetitive Substring
·1 分鐘
LeetCode
Medium
Sliding-Window
String
LeetCode 2730 解題筆記:視窗裡最多一組相鄰相同的數字;新的一組進來就縮左邊,直到移出前一組
LeetCode 2516: Take K of Each Character From Left and Right
·1 分鐘
LeetCode
Medium
Sliding-Window
Hash-Table
String
LeetCode 2516 解題筆記:從兩端拿等於中間留一段;留下的每種字元最多是總數 − k,找最長的這種中間視窗
LeetCode 3090: Maximum Length Substring With Two Occurrences
·1 分鐘
LeetCode
Easy
Sliding-Window
Hash-Table
String
LeetCode 3090 解題筆記:「求最長」的滑動視窗,剛加進來的字元超過 2 次就縮左邊
LeetCode 2024: Maximize the Confusion of an Exam
·1 分鐘
LeetCode
Medium
Sliding-Window
String
Binary-Search
Prefix-Sum
LeetCode 2024 解題筆記:視窗合法的條件是 T 和 F 比較少的那個 <= k(把少的全部改掉);不合法就縮左邊
LeetCode 1208: Get Equal Substrings Within Budget
·1 分鐘
LeetCode
Medium
Sliding-Window
String
Binary-Search
Prefix-Sum
LeetCode 1208 解題筆記:每個位置的花費是 |s[i] - t[i]|,題目變成「總和 <= maxCost 的最長子陣列」
LeetCode 1461: Check If a String Contains All Binary Codes of Size K
·1 分鐘
LeetCode
Medium
Hash-Table
String
Bit-Manipulation
Rolling-Hash
LeetCode 1461 解題筆記:把所有長度 k 的子字串丟進集合,大小等於 2^k 就成立;最後一個起點是 len(s) - k
LeetCode 3800: Minimum Cost to Make Two Binary Strings Equal
·1 分鐘
LeetCode
Medium
Greedy
String
LeetCode 3800 解題筆記:不相等的位置分兩類;不同類的兩兩用 swap,同類的兩兩用 cross + swap,剩一個只能 flip,每種都跟兩次 flip 比
LeetCode 3799: Word Squares II
·1 分鐘
LeetCode
Medium
Backtracking
Enumeration
String
LeetCode 3799 解題筆記:四層枚舉,每一層先用角落字母剪枝,排序後輸出自然就是字典序
LeetCode 3798: Largest Even Number
·1 分鐘
LeetCode
Easy
String
LeetCode 3798 解題筆記:偶數只看最後一位,把結尾的 1 刪掉就好;保留越多位數越大
LeetCode 2953: Count Complete Substrings
·2 分鐘
LeetCode
Hard
Sliding-Window
Hash-Table
String
LeetCode 2953 解題筆記:先在相鄰字元差 > 2 的地方切段;每段枚舉有幾種字元 d,視窗長度固定是 d × k,維護「剛好出現 k 次的字元數」
LeetCode 2269: Find the K-Beauty of a Number
·1 分鐘
LeetCode
Easy
Sliding-Window
Math
String
LeetCode 2269 解題筆記:把數字轉成字串,枚舉每個長度 k 的子字串;0 不能當除數
LeetCode 2156: Find Substring With Given Hash Value
·1 分鐘
LeetCode
Hard
Sliding-Window
Rolling-Hash
String
LeetCode 2156 解題筆記:雜湊的第一個字元乘 p^0,從右往左滑動時只要乘 p 再加新字元、扣掉 p^k 倍的出去字元,不需要除法;modulo 不一定是質數,不能用模反元素