01. 数组滑动窗口知识 #21
Replies: 10 comments 1 reply
-
最后一道题的 “count += (right - left + 1)”真是恍然大悟 |
Beta Was this translation helpful? Give feedback.
-
1343 中 right - left + 1 >= k 是否可以写成right - left + 1 == k? 测试所有算例是通过的,按照固定窗口算法其实用==就可以了。我的问题是用==是不是有什么其他我没有考虑到的地方?谢谢 |
Beta Was this translation helpful? Give feedback.
-
209 中
我定义ans = 0,似乎这样最后返回的时候就不用再比较 |
Beta Was this translation helpful? Give feedback.
-
if k <= 1: return 0 |
Beta Was this translation helpful? Give feedback.
-
这里题目要求是乘积小于 k 而不是乘积小于等于 k。[1, 1, 1] k = 1 的情况下,应该是 0。连续子数组中没有乘积小于 1 的,所以答案是 0。 |
Beta Was this translation helpful? Give feedback.
-
最后一道,需要加个条件 while left <= right and window_product >= k。不然 nums = [1,2,3], k = 0 会越界。 |
Beta Was this translation helpful? Give feedback.
-
函数开始位置,当 k <= 1 时,直接返回 0 了。 |
Beta Was this translation helpful? Give feedback.
-
懂了!感谢二位解答 ~ |
Beta Was this translation helpful? Give feedback.
-
可以改成 right - left + 1 == k。两者的边界判断条件是一样的。 |
Beta Was this translation helpful? Give feedback.
-
3.3题,如果求解的平均值换成3,[2,2,8]也满足题目吗? |
Beta Was this translation helpful? Give feedback.
-
01.数组滑动窗口知识 | 算法通关手册
数组滑动窗口知识 # 1. 滑动窗口算法介绍 # 在计算机网络中,滑动窗口协议(Sliding Window Protocol)是传输层进行流控的一种措施,接收方通过通告发送方自己的窗口大小,从而控制发送方的发送速度,从而达到防止发送方发送速度过快而导致自己被淹没的目的。我们所要
https://algo.itcharge.cn/01.Array/05.Array-Sliding-Window/01.Array-Sliding-Window/
Beta Was this translation helpful? Give feedback.
All reactions