↓快轉到主要內容

Math

LeetCode 3824: Minimum K to Reduce Array Within Limit
·1 分鐘
LeetCode Medium Binary-Search Math
LeetCode 3824 解題筆記:對 k 二分,條件是單調的;上界至少要到 n,因為操作次數至少是 n
LeetCode 976: Largest Perimeter Triangle
·1 分鐘
LeetCode Easy Math Greedy Sorting Geometry Array
LeetCode 976 解題筆記:排序後,從最大的開始看連續的三條邊,a + b > c 第一次成立就是最大周長
LeetCode 633: Sum of Square Numbers
·2 分鐘
LeetCode Medium Two-Pointers Math Binary-Search
LeetCode 633 解題筆記:a 從 0、b 從 isqrt(c) 開始對撞;平方和太大 b 減一,太小 a 加一;注意 0 也算、a 可以等於 b、浮點數開根號的誤差
LeetCode 1040: Moving Stones Until Consecutive II
·1 分鐘
LeetCode Medium Sliding-Window Math Sorting Array
LeetCode 1040 解題筆記:最多步數 = 總空位 − 第一步會浪費掉的那一邊空隙;最少步數用長度 n 的視窗找最多石頭,n - 1 顆已連續、剩一顆在遠處時要特判成 2
LeetCode 3805: Count Caesar Cipher Pairs
·1 分鐘
LeetCode Medium Math Hash-Table String Counting
LeetCode 3805 解題筆記:把每個字串整串平移到第一個字母是 a,凱薩等價的字串會變成一樣;再數每種正規化結果的配對數
LeetCode 1401: Circle and Rectangle Overlapping
·1 分鐘
LeetCode Medium Math Geometry
LeetCode 1401 解題筆記:矩形裡離圓心最近的點,是把圓心的座標 clamp 到矩形範圍內;這個點到圓心的距離 <= 半徑就重疊
LeetCode 2269: Find the K-Beauty of a Number
·1 分鐘
LeetCode Easy Sliding-Window Math String
LeetCode 2269 解題筆記:把數字轉成字串,枚舉每個長度 k 的子字串;0 不能當除數
LeetCode 1281: Subtract the Product and Sum of Digits of an Integer
·1 分鐘
LeetCode Easy Math
LeetCode 1281 解題筆記:一次走過所有位數,同時累積積與和,回傳積減和
LeetCode 1512: Number of Good Pairs
·1 分鐘
LeetCode Easy Math Hash-Table Counting Array
LeetCode 1512 解題筆記:邊掃邊數,每個數可以跟前面每個相同的數配一對,答案加上目前的出現次數
LeetCode 1486: XOR Operation in an Array
·1 分鐘
LeetCode Easy Math Bit-Manipulation
LeetCode 1486 解題筆記:依定義產生 start + 2i,逐一 XOR 起來
LeetCode 2469: Convert the Temperature
·1 分鐘
LeetCode Easy Math
LeetCode 2469 解題筆記:直接套公式,Kelvin = C + 273.15,Fahrenheit = C × 1.8 + 32
LeetCode 2413: Smallest Even Multiple
·1 分鐘
LeetCode Easy Math Number-Theory
LeetCode 2413 解題筆記:lcm(2, n);n 是偶數就是 n,奇數就是 2n