[LC] 359. Logger Rate Limiter
Design a logger system that receive stream of messages along with its timestamps, each message should be printed if and only if it is not printed in the last 10 seconds.
Given a message and a timestamp (in seconds granularity), return true if the message should be printed in the given timestamp, otherwise returns false.
It is possible that several messages arrive roughly at the same time.
class Logger {
private Map<String, Integer> map;
/** Initialize your data structure here. */
public Logger() {
map = new HashMap<>();
}
/** Returns true if the message should be printed in the given timestamp, otherwise returns false.
If this method returns false, the message will not be printed.
The timestamp is in seconds granularity. */
public boolean shouldPrintMessage(int timestamp, String message) {
if (!map.containsKey(message) || timestamp - map.get(message) >= 10) {
map.put(message, timestamp);
return true;
}
return false;
}
}
/**
* Your Logger object will be instantiated and called as such:
* Logger obj = new Logger();
* boolean param_1 = obj.shouldPrintMessage(timestamp,message);
*/
[LC] 359. Logger Rate Limiter的更多相关文章
- 359. Logger Rate Limiter
/* * 359. Logger Rate Limiter * 2016-7-14 by Mingyang * 很简单的HashMap,不详谈 */ class Logger { HashMap< ...
- LeetCode 359 Logger Rate Limiter
Problem: Design a logger system that receive stream of messages along with its timestamps, each mess ...
- LeetCode 359. Logger Rate Limiter (记录速率限制器)$
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
- [LeetCode] 359. Logger Rate Limiter 记录速率限制器
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
- 【LeetCode】359. Logger Rate Limiter 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode ...
- Logger Rate Limiter 十秒限时计数器
[抄题]: Design a logger system that receive stream of messages along with its timestamps, each message ...
- [LeetCode] Logger Rate Limiter 记录速率限制器
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
- LeetCode Logger Rate Limiter
原题链接在这里:https://leetcode.com/problems/logger-rate-limiter/ 题目: Design a logger system that receive s ...
- Logger Rate Limiter -- LeetCode
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
随机推荐
- 北邮14&18年软院机试【参考】答案
2014 Problem A. 奇偶求和 题目描述: 给定N个数,分别求出这N个数中奇数的和以及偶数的和. 输入格式 第一行为测试数据的组数T(1<=T<=50).请注意,任意两组测试数据 ...
- Ubuntu18.04 有线无法正常上网(请读完全文再进行操作)
电脑Windows10+Ubuntu18.04双系统,一直都没问题,前段时间突然在Ubuntu系统下有线连接失败,但是在Windows下可以正常上网. 今天尝试进行了修复. 在终端通过ifconfig ...
- 学习Unet的一些过程
毕业设计的项目,需要用到手机作为控制端,这就需要用到Unity的网络模块. 因为只会设计到几个简单的按钮命令,所以不打算做多么复杂的功能,一开始打算用C#的Socket编程,但是考虑到多线程的关系觉得 ...
- gitlab命令详解
http://www.ruanyifeng.com/blog/2014/06/git_remote.html
- LinuxC++开发记录(g++)
g++使用 1. 编译过程 预处理(-E) 编译(-S) 汇编(-c) 链接 1.1 预处理(-E) 为了直观的了解预处理,理解预处理做了哪些工作,不说那么多,直接上代码,创建main.h与main. ...
- 吴裕雄--天生自然MySQL学习笔记:MySQL简介
MySQL 是最流行的关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System:关系数据库管理系统)应用 ...
- aws ec2 安装Elastic search 7.2.0 kibana 并配置 hanlp 分词插件
文章大纲 Elastic search & kibana & 分词器 安装 版本控制 下载地址 Elastic search安装 kibana 安装 分词器配置 Elastic sea ...
- python中的倒序遍历
1.在列表本身倒序 a = [1, 3, 7, 5, 2, 6] a.reverse() # 在列表本身进行倒序,不返回新的值 print(a) # 输出a: # [6, 2, 5, 7, 3, 1] ...
- Maven--仓库的分类
对于 Maven 仓库来说,仓库只分为两类:本地仓库和远程仓库. 当 Maven 根据坐标寻找构件的时候,它首先会查看本地仓库,如果本地仓库存在此构件,则直接使用:如果本地仓库不存在此构件,或者需要查 ...
- protobuf使用遇到的坑
在这里具体的使用我不写了,可以参考下面接个连接,我只记录自己遇到的问题. https://www.cnblogs.com/autyinjing/p/6495103.html(此博客很详细,不过最好不要 ...