↓快轉到主要內容

LeetCode

LeetCode 1480: Running Sum of 1d Array
·1 分鐘
LeetCode Easy Array Prefix-Sum
LeetCode 1480 解題筆記:前綴和的定義,每一格加上前一格
LeetCode 1413: Minimum Value to Get Positive Step by Step Sum
·1 分鐘
LeetCode Easy Array Prefix-Sum
LeetCode 1413 解題筆記:起始值加上每個前綴和都要 >= 1,所以起始值是 max(1, 1 - 最小前綴和)
LeetCode 2335: Minimum Amount of Time to Fill Cups
·1 分鐘
LeetCode Easy Array Greedy Sorting Heap-Priority-Queue
LeetCode 2335 解題筆記:答案是 max(最多的那種, ceil(總數 / 2));模擬的話每秒從最多的兩種各裝一杯
LeetCode 2231: Largest Number After Digit Swaps by Parity
·1 分鐘
LeetCode Easy Sorting Heap-Priority-Queue
LeetCode 2231 解題筆記:奇數位數只能跟奇數交換、偶數只能跟偶數交換;分別排序後,依原本每個位置的奇偶放回最大的
LeetCode 2099: Find Subsequence of Length K With the Largest Sum
·1 分鐘
LeetCode Easy Array Hash-Table Sorting Heap-Priority-Queue
LeetCode 2099 解題筆記:選出最大的 k 個數(連同 index),再按 index 排回原本的順序
LeetCode 1791: Find Center of Star Graph
·1 分鐘
LeetCode Easy Graph
LeetCode 1791 解題筆記:中心點出現在每一條邊上,所以只要看前兩條邊的共同點
LeetCode 2357: Make Array Zero by Subtracting Equal Amounts
·1 分鐘
LeetCode Easy Array Hash-Table Greedy Sorting
LeetCode 2357 解題筆記:每次操作會讓最小的正數那一群變成 0,所以次數就是不同的正數有幾種
LeetCode 1464: Maximum Product of Two Elements in an Array
·1 分鐘
LeetCode Easy Array Sorting Heap-Priority-Queue
LeetCode 1464 解題筆記:值都是正數,取最大的兩個數 a、b,答案是 (a - 1)(b - 1)
LeetCode 1337: The K Weakest Rows in a Matrix
·1 分鐘
LeetCode Easy Array Binary-Search Sorting Heap-Priority-Queue
LeetCode 1337 解題筆記:每列的士兵都在前面,用二分找第一個 0 就是士兵數;照(士兵數, 列號)排序取前 k 個
LeetCode 165: Compare Version Numbers
·1 分鐘
LeetCode Medium Two-Pointers String
LeetCode 165 解題筆記:用 . 切開後轉成整數逐段比較,比較短的版本缺的段當作 0
LeetCode 109: Convert Sorted List to Binary Search Tree
·1 分鐘
LeetCode Medium Linked-List Divide-and-Conquer Tree Binary-Search-Tree
LeetCode 109 解題筆記:快慢指針找中點當根,左右兩半遞迴建樹;高度自然平衡
LeetCode 236: Lowest Common Ancestor of a Binary Tree
·1 分鐘
LeetCode Medium Tree Depth-First-Search Binary-Tree Binary-Lifting
LeetCode 236 解題筆記:遞迴回傳子樹裡找到的 p 或 q;左右都找到代表在這裡分岔,這個節點就是 LCA