Skip to content

Commit 04d4291

Browse files
committed
✨feat: add 剑指 Offer 59
1 parent 104901b commit 04d4291

7 files changed

+257
-6
lines changed

Index/分块.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
| 题目 | 题解 | 难度 | 推荐指数 |
22
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
3+
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
34
| [933. 最近的请求次数](https://leetcode-cn.com/problems/number-of-recent-calls/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/number-of-recent-calls/solution/by-ac_oier-evqe/) | 简单 | 🤩🤩🤩🤩🤩 |
45
| [729. 我的日程安排表 I](https://leetcode.cn/problems/my-calendar-i/) | [LeetCode 题解链接](https://leetcode.cn/problems/my-calendar-i/solution/by-ac_oier-hnjl/) | 中等 | 🤩🤩🤩🤩 |
56
| [732. 我的日程安排表 III](https://leetcode-cn.com/problems/my-calendar-iii/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/my-calendar-iii/solution/by-ac_oier-cv31/) | 困难 | 🤩🤩🤩 |
7+
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |
68

Index/单调队列.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
| 题目 | 题解 | 难度 | 推荐指数 |
22
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
3+
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
34
| [1438. 绝对差不超过限制的最长连续子数组](https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/solution/xiang-jie-er-fen-hua-dong-chuang-kou-dan-41g1/) | 中等 | 🤩🤩🤩 |
5+
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |
46

Index/堆.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
33
| [23. 合并K个升序链表](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/merge-k-sorted-lists/solution/shua-chuan-lc-you-xian-dui-lie-jie-fa-sh-3flb/) | 困难 | 🤩🤩🤩 |
44
| [218. 天际线问题](https://leetcode-cn.com/problems/the-skyline-problem/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/the-skyline-problem/solution/gong-shui-san-xie-sao-miao-xian-suan-fa-0z6xc/) | 困难 | 🤩🤩🤩 |
5+
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
56
| [264. 丑数 II](https://leetcode-cn.com/problems/ugly-number-ii/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/ugly-number-ii/solution/gong-shui-san-xie-yi-ti-shuang-jie-you-x-3nvs/) | 中等 | 🤩🤩🤩 |
67
| [295. 数据流的中位数](https://leetcode-cn.com/problems/find-median-from-data-stream/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/find-median-from-data-stream/solution/gong-shui-san-xie-jing-dian-shu-ju-jie-g-pqy8/) | 中等 | 🤩🤩🤩🤩 |
78
| [313. 超级丑数](https://leetcode-cn.com/problems/super-ugly-number/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/super-ugly-number/solution/gong-shui-san-xie-yi-ti-shuang-jie-you-x-jyow/) | 中等 | 🤩🤩🤩 |
@@ -26,5 +27,6 @@
2627
| [1705. 吃苹果的最大数目](https://leetcode-cn.com/problems/maximum-number-of-eaten-apples/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-number-of-eaten-apples/solution/gong-shui-san-xie-noxiang-xin-ke-xue-xi-hfdy0/) | 中等 | 🤩🤩🤩🤩🤩 |
2728
| [1834. 单线程 CPU](https://leetcode-cn.com/problems/single-threaded-cpu/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/single-threaded-cpu/solution/gong-shui-san-xie-shu-ju-jie-gou-yun-yon-1qk0/) | 中等 | 🤩🤩🤩🤩 |
2829
| [剑指 Offer 41. 数据流中的中位数](https://leetcode.cn/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/solution/by-ac_oier-exn5/) | 困难 | 🤩🤩🤩🤩🤩 |
30+
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |
2931
| [面试题 17.14. 最小K个数](https://leetcode-cn.com/problems/smallest-k-lcci/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/smallest-k-lcci/solution/gong-shui-san-xie-yi-ti-si-jie-you-xian-yy5k5/) | 中等 | 🤩🤩🤩🤩 |
3032

Index/线段树.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| 题目 | 题解 | 难度 | 推荐指数 |
22
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
3+
| [239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) | [LeetCode 题解链接](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/) | 困难 | 🤩🤩🤩🤩🤩 |
34
| [307. 区域和检索 - 数组可修改](https://leetcode-cn.com/problems/range-sum-query-mutable/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/range-sum-query-mutable/solution/by-ac_oier-zmbn/) | 中等 | 🤩🤩🤩🤩🤩 |
45
| [327. 区间和的个数](https://leetcode.cn/problems/count-of-range-sum/) | [LeetCode 题解链接](https://leetcode.cn/problems/count-of-range-sum/solution/by-ac_oier-b36o/) | 困难 | 🤩🤩🤩🤩🤩 |
56
| [654. 最大二叉树](https://leetcode.cn/problems/maximum-binary-tree/) | [LeetCode 题解链接](https://leetcode.cn/problems/maximum-binary-tree/solution/by-ac_oier-s0wc/) | 中等 | 🤩🤩🤩🤩🤩 |
@@ -12,4 +13,5 @@
1213
| [1109. 航班预订统计](https://leetcode-cn.com/problems/corporate-flight-bookings/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/corporate-flight-bookings/solution/gong-shui-san-xie-yi-ti-shuang-jie-chai-fm1ef/) | 中等 | 🤩🤩🤩🤩🤩 |
1314
| [1893. 检查是否区域内所有整数都被覆盖](https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/solution/gong-shui-san-xie-yi-ti-shuang-jie-mo-ni-j83x/) | 简单 | 🤩🤩🤩🤩 |
1415
| [2213. 由单个字符重复的最长子字符串](https://leetcode-cn.com/problems/longest-substring-of-one-repeating-character/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/longest-substring-of-one-repeating-character/solution/by-ac_oier-0lso/) | 困难 | 🤩🤩🤩🤩🤩 |
16+
| [剑指 Offer 59 - I. 滑动窗口的最大值](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/solution/by-ac_oier-sjym/) | 困难 | 🤩🤩🤩🤩🤩 |
1517

LeetCode/231-240/239. 滑动窗口最大值(困难).md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### 题目描述
22

3-
这是 LeetCode 上的 **[239. 滑动窗口最大值]()** ,难度为 **困难**
3+
这是 LeetCode 上的 **[239. 滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/solution/by-ac_oier-o89l/)** ,难度为 **困难**
44

55
Tag : 「优先队列(堆)」、「线段树」、「分块」、「单调队列」、「RMQ」
66

LeetCode/791-800/793. 阶乘函数后 K 个零(困难).md

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ Tag : 「数学」、「二分」、「容斥原理」
4242

4343
### 数学 + 二分
4444

45-
对于一个 $n! = 1 \times 2 \times ... \times (n - 1) \times n$ 而言,其最终结果尾部包含 $0$ 的数量取决于其被累乘 $10$ 的次数,而 $10$ 可通过质因数 $2$ 和 $5$ 相乘而来,因此假设对 $n!$ 中的每一数进行阶乘分解,最终分解出 $2^p$ 和 $5^q$ 的话,那么最终结果尾部包含 $0$ 的个数为 $q$ 个(可证明 $p <= q$ 始终满足)。
45+
对于一个 $n! = 1 \times 2 \times ... \times (n - 1) \times n$ 而言,其最终结果尾部包含 $0$ 的数量取决于其被累乘 $10$ 的次数,而 $10$ 可通过质因数 $2$ 和 $5$ 相乘而来,因此假设对 $n!$ 进行阶乘分解,最终分解出 $2^p$ 和 $5^q$ 的话,那么最终结果尾部包含 $0$ 的个数为 $q$ 个(可证明 $p >= q$ 始终满足)。
4646

47-
因此原问题转化为:在非负整数中,有多少个数进行阶乘分解后,所含质因数 $5$ 的个数为 $k$ 个。
47+
因此原问题转化为:在非负整数中,有多少个数进行阶乘分解后,所含质因数 $5$ 的个数恰好为 $k$ 个。
4848

4949
同时我们可知:随着 $n$ 的增大,其所能分解出来的 $5$ 的个数必然是递增的。
5050

51-
基于此,我们可以通过「二分 + 容斥原理」来得出分解 $5$ 个数恰好为 $k$ 的连续段长度。假设我们存在函数 `f(k)` 可得到非负整数中分解 $5$ 个数为小于等于 `k` 的个数,那么最终 `f(k) - f(k - 1)` 即答案
51+
基于此,我们可以通过「二分 + 容斥原理」来得出分解 $5$ 个数恰好为 $k$ 的连续段长度。假设我们存在函数 `f(k)` 可得到非负整数中分解 $5$ 个数为小于等于 `k` 的个数,那么最终 `f(k) - f(k - 1)` 即是答案
5252

53-
在单调函数上求解小于等于 `k` 分割点,可通过「二分」来做剩下的问题是,如何求得给定 `x` 时,其阶乘分解所包含 $5$ 个个数,这可以通过 $O(\log{x})$ 的筛法来做。
53+
在单调函数上求解小于等于 `k` 分割点,可通过「二分」来做剩下的问题是,如何求得给定 `x` 时,其阶乘分解所包含 $5$ 个个数,这可以通过 $O(\log{x})$ 的筛法来做。
5454

5555
最后还要确定二分的值域,由于我们是求阶乘分解中 $5$ 的个数,因此值域的上界为 $5k$,利用 $k$ 的范围为 $1e9$,直接取成 $1e10$ 即可。
5656

@@ -102,7 +102,7 @@ function getCnt(x: bigint): bigint {
102102
return ans
103103
}
104104
```
105-
* 时间复杂度:$O(\log{k})$
105+
* 时间复杂度:$O(\log^2{k})$
106106
* 空间复杂度:$O(1)$
107107

108108
---

0 commit comments

Comments
 (0)