LeetCode
LeetCode 3090: Maximum Length Substring With Two Occurrences
·1 分鐘
LeetCode
Easy
Sliding-Window
Hash-Table
String
LeetCode 3090 解題筆記:「求最長」的滑動視窗,剛加進來的字元超過 2 次就縮左邊
LeetCode 2958: Length of Longest Subarray With at Most K Frequency
·1 分鐘
LeetCode
Medium
Sliding-Window
Hash-Table
Array
LeetCode 2958 解題筆記:「求最長」的滑動視窗,剛加入的數字出現超過 k 次就縮左邊
LeetCode 220: Contains Duplicate III
·2 分鐘
LeetCode
Hard
Sliding-Window
Bucket-Sort
Ordered-Set
Sorting
Array
LeetCode 220 解題筆記:桶大小設成 valueDiff + 1,同一個桶裡的兩個數一定符合;只要再看相鄰兩個桶。視窗只保留最近 indexDiff 個數,所以每個桶最多一個數
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 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 的位置