Medium
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 865: Smallest Subtree with all the Deepest Nodes
·1 分鐘
LeetCode
Medium
Tree
Binary-Tree
Bfs
Dfs
Lca
LeetCode 865 解題筆記:BFS 找最後一層再一起往上爬,或一次 DFS 回傳 (深度, 節點)
LeetCode 1339: Maximum Product of Splitted Binary Tree
·1 分鐘
LeetCode
Medium
Tree
Binary-Tree
Dfs
LeetCode 1339 解題筆記:先算總和,再枚舉每棵子樹的和,不要改到輸入
LeetCode 1975: Maximum Matrix Sum
·1 分鐘
LeetCode
Medium
Greedy
Matrix
Array
LeetCode 1975 解題筆記:負號可以兩兩搬到任何位置,但負數個數的奇偶不變;奇數個時留一個在絕對值最小的位置
LeetCode 1161: Maximum Level Sum of a Binary Tree
·1 分鐘
LeetCode
Medium
Tree
Binary-Tree
Bfs
LeetCode 1161 解題筆記:把 None 放進下一層會多出一層假的總和 0
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 1401: Circle and Rectangle Overlapping
·1 分鐘
LeetCode
Medium
Math
Geometry
LeetCode 1401 解題筆記:矩形裡離圓心最近的點,是把圓心的座標 clamp 到矩形範圍內;這個點到圓心的距離 <= 半徑就重疊
LeetCode 1306: Jump Game III
·1 分鐘
LeetCode
Medium
Bfs
Dfs
Graph
Array
LeetCode 1306 解題筆記:每個 index 是節點、往左右跳是邊,BFS 或 DFS 看能不能走到值為 0 的位置
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 1016: Binary String With Substrings Representing 1 To N
·2 分鐘
LeetCode
Medium
Sliding-Window
String
Bit-Manipulation
Hash-Table
LeetCode 1016 解題筆記:s 最多 1000 個字元,長度固定時的子字串數量有限,n 太大一定是 False;從 n 往下檢查會很快失敗,或從每個起點往右最多延伸 30 位收集所有 <= n 的值
LeetCode 3796: Find Maximum Value in a Constrained Sequence
·1 分鐘
LeetCode
Medium
Greedy
Array
LeetCode 3796 解題筆記:每個位置的上界是自己的限制、左邊上界 + 差值、右邊上界 + 差值三者取最小;左右各掃一次