復(fù)盤|第315場周賽
6204. 與對應(yīng)負(fù)數(shù)同時存在的最大正整數(shù)?https://leetcode.cn/problems/largest-positive-integer-that-exists-with-its-negative/
【哈希表】此題,排序做法O(nlogn),遍歷做法O(n),所以一次遍歷即可,一邊判斷-num是否在哈希表里,一邊往哈希表里加num。
6205. 反轉(zhuǎn)之后不同整數(shù)的數(shù)目?https://leetcode.cn/problems/count-number-of-distinct-integers-after-reverse-operations/
【哈希表】哈希表存num和reverse(num),統(tǒng)計length即可。注意到python的int(str(x)[::-1])調(diào)用底層c庫實現(xiàn),比手動實現(xiàn)翻轉(zhuǎn)要快。
6219. 反轉(zhuǎn)之后的數(shù)字和?https://leetcode.cn/problems/sum-of-number-and-its-reverse/
【模擬】手動實現(xiàn)數(shù)字反轉(zhuǎn)。
調(diào)庫實現(xiàn)數(shù)字反轉(zhuǎn)。
2444. 統(tǒng)計定界子數(shù)組的數(shù)目?https://leetcode.cn/problems/count-subarrays-with-fixed-bounds/
【枚舉】將[minK, maxK]范圍之外的數(shù)作為分割點。在每兩個分割點之間,枚舉子數(shù)組的右端點,minK和maxK最早出現(xiàn)的位置記作idx,idx左側(cè)到左分割點之間都能作為左端點。(代碼中手寫min/max比調(diào)庫更快)