原文链接: https://leetcode-cn.com/problems/find-median-from-data-stream 英文原文The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. For exam…
标签详情
数据流 分类
原文链接: https://leetcode-cn.com/problems/kth-largest-element-in-a-stream 英文原文Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest cla…
原文链接: https://leetcode-cn.com/problems/online-stock-span 英文原文Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day. The span of the stock's price today is defined as the max…
原文链接: 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/stream-of-characters 英文原文Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words. For example, if words = ["abc", "xyz"] a…
原文链接: 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/design-browser-history 英文原文You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps. Imp…
原文链接: 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/design-an-ordered-stream 英文原文There is a stream of n (idKey, value) pairs arriving in an arbitrary order, where idKey is an integer between 1 and n and value is a string. No two pairs have the same id. Design a s…
原文链接: https://leetcode-cn.com/problems/continuous-median-lcci 英文原文Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated. Median is the middle value in an ordered integ…
原文链接: https://leetcode-cn.com/problems/rank-from-stream-lcci 英文原文Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal to x). lmplement the data s…
原文链接: 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] 内发生的请求数。 保证…
原文链接: https://leetcode-cn.com/problems/jBjn9C 中文题目设计一个找到数据流中第 k 大元素的类(class)。注意是排序后的第 k 大元素,不是第 k 个不同的元素。 请实现 KthLargest 类: KthLargest(int k, int[] nums) 使用整数 k 和整数流 nums 初始化对象。 int add(int val) 将 val 插入数据流 nums 后,返回当前数据流中第 k 大的元素。 示例: 输入: ["KthLarge…