Hash-Table
LeetCode 3843: First Element with Unique Frequency
·1 分鐘
LeetCode
Medium
Hash-Table
Counting
Array
LeetCode 3843 解題筆記:數每個值的次數,再數「每種次數有幾個值」;由左到右第一個次數只屬於它自己的就是答案
LeetCode 3842: Toggle Light Bulbs
·1 分鐘
LeetCode
Easy
Hash-Table
Simulation
Array
LeetCode 3842 解題筆記:用集合切換開關,或數出現奇數次的燈泡;最後要排序
LeetCode 3839: Number of Prefix Connected Groups
·1 分鐘
LeetCode
Medium
Hash-Table
String
Counting
LeetCode 3839 解題筆記:前 k 個字元相同的字互相連通,用 word[:k] 當 key 計數;長度不到 k 的字要排除
LeetCode 3719: Longest Balanced Subarray I
·1 分鐘
LeetCode
Medium
Hash-Table
Prefix-Sum
Segment-Tree
Array
LeetCode 3719 解題筆記:n 只有 1500,固定左端點往右擴,用兩個集合增量維護不同的奇數和偶數
LeetCode 1570: Dot Product of Two Sparse Vectors
·1 分鐘
LeetCode
Medium
Two-Pointers
Design
Hash-Table
Array
LeetCode 1570 解題筆記:只存非零的 (index, value),內積時用雙指針合併兩個依 index 排序的列表,index 相同才相乘
LeetCode 244: Shortest Word Distance II
·1 分鐘
LeetCode
Medium
Two-Pointers
Design
Hash-Table
String
Array
LeetCode 244 解題筆記:預處理每個字的出現位置(天然排序),查詢時對兩個位置列表做雙指針合併,每次移動比較小的那個
LeetCode 442: Find All Duplicates in an Array
·1 分鐘
LeetCode
Medium
Hash-Table
Array
LeetCode 442 解題筆記:值在 1..n,用 nums[v-1] 的負號記錄 v 出現過;第二次遇到時它已經是負的
LeetCode 41: First Missing Positive
·2 分鐘
LeetCode
Hard
Hash-Table
Array
LeetCode 41 解題筆記:答案一定在 1..n+1;把不可能的值換成 n+1(不能用 0),用 nums[v-1] 的負號標記 v 出現過
LeetCode 3684: Maximize Sum of At Most K Distinct Elements
·1 分鐘
LeetCode
Easy
Greedy
Sorting
Hash-Table
LeetCode 3684 解題筆記:全是正數,去重後由大到小取前 k 個
LeetCode 2273: Find Resultant Array After Removing Anagrams
·1 分鐘
LeetCode
Easy
Hash-Table
String
Sorting
LeetCode 2273 解題筆記:一直刪掉跟前一個是異位詞的字,等於只保留跟前一個留下來的字不是異位詞的字;用排序後的字串比較
LeetCode 2122: Recover the Original Array
·2 分鐘
LeetCode
Hard
Two-Pointers
Sorting
Hash-Table
Enumeration
Array
LeetCode 2122 解題筆記:最小的數一定在 lower,枚舉它的配對決定 k;排序後用兩個指針把每個最小的未配對數配給 +2k 的數
LeetCode 923: 3Sum With Multiplicity
·3 分鐘
LeetCode
Medium
Two-Pointers
Sorting
Hash-Table
Counting
Array
LeetCode 923 解題筆記:排序後固定第一個數、對撞指針找另外兩個;兩端值相同時用組合數一次算完,不同時把兩端各自的重複數相乘