当前位置:网站首页>[leetcode 239] sliding window
[leetcode 239] sliding window
2022-06-30 11:01:00 【Salmon_ lee】
Ideas : A monotonous queue
- Maintain a two terminal queue , Store subscripts , The corresponding elements are in decreasing order .
- For each window , The maximum value is the first element of the monotone queue .
class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
window = collections.deque()
ans = list()
for i, x in enumerate(nums):
# Pop up values not in the interval
if i >= k and window[0] <= i - k:
window.popleft()
# Maintain monotonous queues
while window and nums[window[-1]] <= x:
window.pop()
window.append(i)
# Store results
if i >= k - 1:
ans.append(nums[window[0]])
return ans边栏推荐
- LVGL 8.2 Image styling and offset
- LVGL 8.2 Simple Colorwheel
- matplotlib 笔记: contourf & contour
- 腾讯云数据库工程师能力认证重磅推出,各界共话人才培养难题
- Problems and solutions in pyinstall packaging for pychart project
- LVGL 8.2图片缩放及旋转
- OLAP数据库引擎如何选型?
- SQL必需掌握的100个重要知识点:使用子查询
- Q-Learning笔记
- [rust daily] several new libraries were released on January 23, 2021
猜你喜欢

苹果高管公然“开怼”:三星抄袭 iPhone,只加了个大屏

The life, working principle and application of electrochemical oxygen sensor

在IPhone12的推理延迟仅为1.6 ms!Snap等详析Transformer结构延迟,并用NAS搜出移动设备的高效网络结构...

Pytorch Notebook. Nn. Batchnorm1d

数据库什么时候需要使用索引【杭州多测师】【杭州多测师_王sir】

ArrayList与顺序表

20万奖金池!【阿里安全 × ICDM 2022】大规模电商图上的风险商品检测赛火热报名中!...

scratch绘制正方形 电子学会图形化编程scratch等级考试二级真题和答案解析2022年6月

Sarsa笔记

数学知识复习:第二型曲线积分
随机推荐
Machine learning interview preparation (I) KNN
[STL source code analysis] container (to be supplemented)
Q-Learning笔记
第一届中国数字藏品大会即将召开
[proteus simulation] Arduino uno led simulated traffic light
SQL必需掌握的100个重要知识点:联结表
Typescript – classes in Es5, inheritance, static methods
Unity Shader - 踩坑 - BRP 管线中的 depth texture 的精度问题(暂无解决方案,推荐换 URP)
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
我们公司使用 7 年的这套通用解决方案,打通了几十个系统,稳的一批!
软件测试工程师面试基础题(应届生和测试小菜必备)最基础的面试题
Algorithme leetcode 86. Liste des liens séparés
The precision problem of depth texture in unity shader - stepping pit - BRP pipeline (there is no solution, it is recommended to replace URP)
Lvgl 8.2 picture scaling and rotation
Google 辟谣放弃 TensorFlow,它还活着!
Sarsa笔记
Double-DQN笔记
Mysql database foundation: TCL transaction control language
pytorch 笔记:validation ,model.eval V.S torch.no_grad
Qt之实现QQ天气预报窗体翻转效果