原文链接: https://leetcode-cn.com/problems/implement-queue-using-stacks 英文原文Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implemen…
标签详情
队列 分类
原文链接: https://leetcode-cn.com/problems/sliding-window-maximum 英文原文You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the wi…
原文链接: https://leetcode-cn.com/problems/flatten-nested-list-iterator 英文原文You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatt…
原文链接: https://leetcode-cn.com/problems/first-unique-character-in-a-string 英文原文Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example 1: Input: s = "leetcode" Output: 0 Example 2: …
原文链接: https://leetcode-cn.com/problems/design-circular-queue 英文原文Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and th…
原文链接: https://leetcode-cn.com/problems/shortest-subarray-with-sum-at-least-k 英文原文Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return…
原文链接: https://leetcode-cn.com/problems/number-of-recent-calls 英文原文You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: RecentCounter() Initializes the counter with z…
原文链接: https://leetcode-cn.com/problems/stamping-the-sequence 英文原文You are given two strings stamp and target. Initially, there is a string s of length target.length with all s[i] == '?'. In one turn, you can place stamp over s and replace every letter…
原文链接: https://leetcode-cn.com/problems/reveal-cards-in-increasing-order 英文原文You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i]. You can order the deck in any ord…
原文链接: https://leetcode-cn.com/problems/constrained-subsequence-sum 英文原文Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums…
原文链接: https://leetcode-cn.com/problems/product-of-the-last-k-numbers 英文原文Design an algorithm that accepts a stream of integers and retrieves the product of the last k integers of the stream. Implement the ProductOfNumbers class: ProductOfNumbers() In…
原文链接: https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit 英文原文Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute diffe…
原文链接: https://leetcode-cn.com/problems/max-value-of-equation 英文原文You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <= points.lengt…
原文链接: https://leetcode-cn.com/problems/design-front-middle-back-queue 英文原文Design a queue that supports push and pop operations in the front, middle, and back. Implement the FrontMiddleBack class: FrontMiddleBack() Initializes the queue. void pushFron…
原文链接: https://leetcode-cn.com/problems/time-needed-to-buy-tickets 英文原文There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed…
原文链接: https://leetcode-cn.com/problems/implement-queue-using-stacks-lcci 英文原文Implement a MyQueue class which implements a queue using two stacks. Example: MyQueue queue = new MyQueue(); queue.push(1); queue.push(2); queue.peek(); // return 1 queue.po…
原文链接: https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof 中文题目用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) 示例 1: 输入: ["CQueue","appendTail","deleteHead","deleteH…
原文链接: https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof 中文题目在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。 示例 1: 输入:s = "abaccdeff" 输出:'b' 示例 2: 输入:s = "" 输出:' ' 限制: 0 <= s 的长度 <= 50000 通过代码 高赞题解本题考察 哈希表 的使用,本文介绍 哈希表 和 有序哈希表 …
原文链接: https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof 中文题目请定义一个队列并实现函数 max_value 得到队列里的最大值,要求函数max_value、push_back 和 pop_front 的均摊时间复杂度都是O(1)。 若队列为空,pop_front 和 max_value 需要返回 -1 示例 1: 输入: ["MaxQueue","push_back","push_back","max_value","…
原文链接: https://leetcode-cn.com/problems/er94lq 英文原文 中文题目秋日市集上,魔术师邀请小扣与他互动。魔术师的道具为分别写有数字 `1~N` 的 `N` 张卡牌,然后请小扣思考一个 `N` 张卡牌的排列 `target`。 魔术师的目标是找到一个数字 k(k >= 1),使得初始排列顺序为 1~N 的卡牌经过特殊的洗牌方式最终变成小扣所想的排列 target,特殊的洗牌方式为: 第一步,魔术师将当前位于 偶数位置 的卡牌(下标自 1 开始),…
原文链接: https://leetcode-cn.com/problems/qIsx9U 中文题目给定一个整数数据流和一个窗口大小,根据该滑动窗口的大小,计算滑动窗口里所有数字的平均值。 实现 MovingAverage 类: MovingAverage(int size) 用窗口大小 size 初始化对象。 double next(int val) 成员函数 next 每次调用的时候都会往滑动窗口增加一个整数,请计算并返回数据流中最后 size 个值的移动平均值,即滑动窗口里所有数字的平均值…
原文链接: https://leetcode-cn.com/problems/H8086Q 中文题目写一个 RecentCounter 类来计算特定时间范围内最近的请求。 请实现 RecentCounter 类: RecentCounter() 初始化计数器,请求数为 0 。 int ping(int t) 在时间 t 添加一个新请求,其中 t 表示以毫秒为单位的某个时间,并返回过去 3000 毫秒内发生的所有请求数(包括新请求)。确切地说,返回在 [t-3000, t] 内发生的请求数。 保证…