
队列
枫流仁武
这个作者很懒,什么都没留下…
展开
-
LeetCode 1438 绝对差不超过限制的最长连续子数组
给你一个整数数组 nums ,和一个表示限制的整数 limit,请你返回最长连续子数组的长度,该子数组中的任意两个元素之间的绝对差必须小于或者等于 limit 。 如果不存在满足条件的子数组,则返回 0 。 示例 1: 输入:nums = [8,2,4,7], limit = 4 输出:2 解释:所有子数组如下: [8] 最大绝对差 |8-8| = 0 <= 4. [8,2] 最大绝对差 |8-2| = 6 > 4. [8,2,4] 最大绝对差 |8-2| = 6 > 4....原创 2021-02-21 14:45:09 · 137 阅读 · 0 评论 -
LeetCode 239 滑动窗口的最大值
给你一个整数数组 nums,有一个大小为k的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k个数字。滑动窗口每次只向右移动一位。 返回滑动窗口中的最大值。 from typing import * from collections import deque class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: que=deque([...原创 2021-01-06 10:28:24 · 72 阅读 · 0 评论 -
1056 Mice and Rice
这道题值得反复思考! 本题代码参考了网上大神的,自己写的远比这复杂的多... 使用队列,通过计数实现了分层操作,每一层淘汰的老鼠rank相等 #include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; stru...原创 2019-07-10 09:29:04 · 142 阅读 · 0 评论 -
PAT 1147
In computer science, aheapis a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...原创 2019-08-20 09:55:59 · 128 阅读 · 0 评论 -
PAT 1091 Acute Stroke
参考了网上的代码 #include <queue> #include <iostream> using namespace std; struct node{ int x,y,z; }; int n,m,h,t; int graph[1290][130][61]; bool visited[1290][130][61]={false}; int X[6]={0,...原创 2019-07-08 15:56:45 · 106 阅读 · 0 评论 -
PAT 1029 Median
在这里注意一下C++的队列和优先队列返回队首元素的不同方式: priority_queue<int,vector<int >,less<>> queue1; queue<int> queue2; queue2.front(); queue1.top(); Given an increasing sequence...原创 2019-07-16 14:20:37 · 144 阅读 · 0 评论