↓快轉到主要內容

Array

LeetCode 1122: Relative Sort Array
·1 分鐘
LeetCode Easy Array Hash-Table Sorting Counting-Sort
LeetCode 1122 解題筆記:計數後先按照 arr2 的順序輸出,剩下的數由小到大接在後面
LeetCode 1089: Duplicate Zeros
·1 分鐘
LeetCode Easy Array Two-Pointers
LeetCode 1089 解題筆記:先數有幾個 0 決定每個數要往後移幾格,再從後往前搬,遇到 0 時把複製的那個 0 也寫進去
LeetCode 1051: Height Checker
·1 分鐘
LeetCode Easy Array Sorting Counting-Sort Bubble-Sort
LeetCode 1051 解題筆記:排序後跟原本的陣列逐一比較,數有幾個位置不同
LeetCode 1046: Last Stone Weight
·1 分鐘
LeetCode Easy Array Heap-Priority-Queue
LeetCode 1046 解題筆記:max-heap(存負數)每次拿出最重的兩顆,不一樣重就把差放回去,最後剩一顆或沒有
LeetCode 1030: Matrix Cells in Distance Order
·1 分鐘
LeetCode Easy Array Math Geometry Sorting
LeetCode 1030 解題筆記:列出所有座標,按到中心的曼哈頓距離排序;回傳的是座標,不是距離
LeetCode 997: Find the Town Judge
·1 分鐘
LeetCode Easy Array Hash-Table Graph
LeetCode 997 解題筆記:法官被其他 n - 1 個人信任而且不信任任何人,所以 in-degree - out-degree == n - 1
LeetCode 1018: Binary Prefix Divisible By 5
·1 分鐘
LeetCode Easy Array Bit-Manipulation
LeetCode 1018 解題筆記:前綴每多一位就是 x = 2x + bit,只要保留 x mod 5,數字不會變大
LeetCode 1013: Partition Array Into Three Parts With Equal Sum
·1 分鐘
LeetCode Easy Array Greedy
LeetCode 1013 解題筆記:總和要能被 3 整除,從左邊累加,每湊到 total / 3 就切一刀,切出至少 3 段就成立
LeetCode 1005: Maximize Sum Of Array After K Negations
·1 分鐘
LeetCode Easy Array Greedy Sorting
LeetCode 1005 解題筆記:每次把最小的數變號;最小的已經是正數時,剩下的次數只要看奇偶
LeetCode 1002: Find Common Characters
·1 分鐘
LeetCode Easy Array Hash-Table String
LeetCode 1002 解題筆記:每個單字各自計數,對所有 Counter 取交集(每個字元取最小次數),再展開
LeetCode 989: Add to Array-Form of Integer
·1 分鐘
LeetCode Easy Array Math
LeetCode 989 解題筆記:把 k 當成進位,從陣列最後一位往前加,k 還沒用完就繼續往前補位
LeetCode 977: Squares of a Sorted Array
·1 分鐘
LeetCode Easy Array Two-Pointers Sorting
LeetCode 977 解題筆記:平方後最大的一定在兩端,左右指針比較兩端的平方,大的從結果的最後面往前填