[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 ...
随机推荐
- Mac技巧-如何切换至 Mac 地图应用的卫星视图模式
如何切换至Mac地图应用的卫星视图模式?很多刚接触MAC电脑的小伙伴并不是很清楚,今天MACW小编就教教大家切换至 Mac 地图应用的卫星视图模式该怎么做.原文:https://www.macw.co ...
- 201604-1 折点计数 Java
思路: 这个题要小心考虑不全.左右两边都比这个数小 或者 左右两边都比这个数大 import java.util.Scanner; public class Main { public static ...
- Web应用和web.xml文件
1.构建Web应用 手动构建一个Web应用: 在任意的目录小创建一个文件夹,例如webDemo 在第一步创建的文件夹中创建一个WEB-INF文件夹(注意大写); 随意找到一个Web应用,将其中的web ...
- NGINX常用模块(二)
5.Nginx日志配置 Nginx有非常灵活的日志记录模式.每个级别的配置可以有各自独立的访问日志.日志格式 通过log_format命令定义格式 1.log_format指令 # 配置语法:包括:e ...
- flask框架-大结局
flask-script 用于实现类似于django中 python3 manage.py runserver ...类似的命令. 安装 pip3 install flask-script 使用: f ...
- Java虚拟机(JVM) - 学习总结(全)
深入理解java虚拟机---学习总结: 1.Java内存区域 1.1 java运行时数据区 Java 虚拟机所管理的内存如下图所示,基于JDK1.6. 基于jdk1.8画的JVM的内存模型 (1) 程 ...
- Python笔记_第二篇_面向过程_第二部分_3.模块的概述
这部分内容是非常重要的,分模块的基本概念和一些常用模块的使用,其实常用模块使用这部分也不是太全面,后续或者有机会再通过其他材料进行讲解. 1. 模块的概述: 目前代码比较少,写在一个文件中还体现不出什 ...
- python3 subprocess 内存操作视频转换流格式
import subprocessout = open('./tmp/sss.mp4','rb').read()p = subprocess.Popen(["./ffmpeg",& ...
- Docker容器化【Dockerfile编写&&搭建与使用Docker私有仓库】
# Docker 学习目标: 掌握Docker基础知识,能够理解Docker镜像与容器的概念 完成Docker安装与启动 掌握Docker镜像与容器相关命令 掌握Tomcat Nginx 等软件的常用 ...
- Intellij IDEA中mybatis-generator自动生成
一.在maven工程中的resource中创建generatorConfig.xml 二.配置generatorConfig.xml: <?xml version="1.0" ...