[LC] 362. Design Hit Counter
Design a hit counter which counts the number of hits received in the past 5 minutes.
Each function accepts a timestamp parameter (in seconds granularity) and you may assume that calls are being made to the system in chronological order (ie, the timestamp is monotonically increasing). You may assume that the earliest timestamp starts at 1.
It is possible that several hits arrive roughly at the same time.
class HitCounter {
Queue<Integer> queue;
/** Initialize your data structure here. */
public HitCounter() {
queue = new LinkedList<>();
}
/** Record a hit.
@param timestamp - The current timestamp (in seconds granularity). */
public void hit(int timestamp) {
queue.offer(timestamp);
}
/** Return the number of hits in the past 5 minutes.
@param timestamp - The current timestamp (in seconds granularity). */
public int getHits(int timestamp) {
while(!queue.isEmpty() && timestamp - queue.peek() >= 300) {
queue.poll();
}
return queue.size();
}
}
/**
* Your HitCounter object will be instantiated and called as such:
* HitCounter obj = new HitCounter();
* obj.hit(timestamp);
* int param_2 = obj.getHits(timestamp);
*/
[LC] 362. Design Hit Counter的更多相关文章
- LeetCode 362. Design Hit Counter
原题链接在这里:https://leetcode.com/problems/design-hit-counter/description/ 题目: Design a hit counter which ...
- [LeetCode] 362. Design Hit Counter 设计点击计数器
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- 【LeetCode】362. Design Hit Counter 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode ...
- 362. Design Hit Counter
这个傻逼题..我没弄明白 you may assume that calls are being made to the system in chronological order (ie, the ...
- [LeetCode] Design Hit Counter 设计点击计数器
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- LeetCode Design Hit Counter
原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...
- Design Hit Counter
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- AN ESAY HIT COUNTER
<?php $counts = ("hitcounter.txt"); $hits = file($counts); $hits[0] ++; $fp = fopen($co ...
- LC 641. Design Circular Deque
Design your implementation of the circular double-ended queue (deque). Your implementation should su ...
随机推荐
- PAT 2011 秋
A : World Cup Betting #include <cstdio> #include <iostream> #include <algorithm> u ...
- @Data与@ConfigurationProperties 简化配置属性数据
参考地址:https://www.cnblogs.com/FraserYu/p/11261916.html 在编写项目代码时,我们要求更灵活的配置,更好的模块化整合.在 Spring Boot 项 ...
- Innodb-内存架构与特性
参考文档 Innodb特性buffer_pool http://mysql.taobao.org/monthly/2017/05/01/?spm=a2c4e.11153940.blogcont2812 ...
- Linux-守护进程的引入
1.进程查看命令ps (1).ps -ajx 偏向显示各种有关的ID号 (2).ps -aux 偏向显示进程各种占用资源 2.向进程发送信号指令kill (1).kill -信号编号 进程ID,向一 ...
- 1013A.Piles With Stones
题目出处:http://codeforces.com/contest/1013/problem/A #include<iostream> using namespace std; int ...
- 利用GetCharWidth32获取字符串宽度
/////////////////////////////////////////////////////////////// // 04FirstWindow.cpp文件 #include < ...
- Reservoir Computing论文学习
目录 背景: RC优势: 储备池计算主要理论组成: ESNS数学模型 结构表示 状态方程和输出方程 计算过程 储备池的优化 GA:使用进化算法对参数进行优化: 基于随机梯度下降法的储备池参数优化 参考 ...
- 第一个----关于GPIO的总结
首先,自己本来报的是单片机的 ,但是因为队友的脑残,给我报成了嵌入式,哎,惨啊,就得从头看这个云里雾里的东西,但是没办法,都报名了 不能呢个交白卷,不然自己就是逃兵了,还有20天就比赛了 我得加 ...
- 吴裕雄--天生自然python TensorFlow图片数据处理:No module named 'tensorflow.examples.tutorials'解决办法
import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...
- [原]win10开机时开启NumLock
修改如下注册表项下的InitialKeyboardIndicators的值为80000002,重启即可. HKEY_USERS\.Default\Control Panel\Keyboard\ HKE ...