Array
LeetCode 3904: Smallest Stable Index II
·1 分鐘
LeetCode
Medium
Prefix-Sum
Array
LeetCode 3904 解題筆記:前綴最大值減後綴最小值 <= k 的第一個 index;後綴最小值先從右往左建好
LeetCode 3903: Smallest Stable Index I
·1 分鐘
LeetCode
Easy
Prefix-Sum
Array
LeetCode 3903 解題筆記:前綴最大值減後綴最小值 <= k 的第一個 index;後綴最小值先從右往左建好
LeetCode 3898: Find the Degree of Each Vertex
·1 分鐘
LeetCode
Easy
Graph
Matrix
Array
LeetCode 3898 解題筆記:鄰接矩陣第 i 列的 1 的個數就是頂點 i 的度數
LeetCode 522: Longest Uncommon Subsequence II
·1 分鐘
LeetCode
Medium
Two-Pointers
String
Sorting
Array
Hash-Table
LeetCode 522 解題筆記:最長的特殊子序列一定是某個完整字串;依長度由長到短檢查,只要不是其他夠長字串的子序列就是答案
LeetCode 1826: Faulty Sensor
·1 分鐘
LeetCode
Easy
Two-Pointers
Array
LeetCode 1826 解題筆記:找到第一個不同的位置後,比對兩種「誰掉了資料」的情況;兩種都成立時無法判斷,回傳 -1
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 3840: House Robber V
·1 分鐘
LeetCode
Medium
Dynamic-Programming
Array
LeetCode 3840 解題筆記:只有相鄰而且同色才衝突;顏色不同直接拿,同色時才做打家劫舍的取捨
LeetCode 3838: Weighted Word Mapping
·1 分鐘
LeetCode
Easy
Array
String
Simulation
LeetCode 3838 解題筆記:每個字的權重加總取 mod 26,再反向對應字母:0 -> z,也就是 chr(ord(‘z’) - r)
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 1229: Meeting Scheduler
·1 分鐘
LeetCode
Medium
Two-Pointers
Sorting
Array
LeetCode 1229 解題筆記:兩個人的時段各自排序後,跟 986 一樣用雙指針找交集;第一個長度夠的交集就是最早的時段