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.
Example:
Logger logger = new Logger();
// logging string "foo" at timestamp 1
logger.shouldPrintMessage(1, "foo"); returns true;
// logging string "bar" at timestamp 2
logger.shouldPrintMessage(2,"bar"); returns true;
// logging string "foo" at timestamp 3
logger.shouldPrintMessage(3,"foo"); returns false;
// logging string "bar" at timestamp 8
logger.shouldPrintMessage(8,"bar"); returns false;
// logging string "foo" at timestamp 10
logger.shouldPrintMessage(10,"foo"); returns false;
// logging string "foo" at timestamp 11
logger.shouldPrintMessage(11,"foo"); returns true;
class Solution {
private Map<String, Integer> ok = new HashMap<>();
public boolean shouldPrintMessage(int timestamp, String message) {
if (timestamp < ok.getOrDefault(message, )) {
return false;
}
ok.put(message, timestamp + );
return true;
}
}
Logger Rate Limiter的更多相关文章
- 359. Logger Rate Limiter
/* * 359. Logger Rate Limiter * 2016-7-14 by Mingyang * 很简单的HashMap,不详谈 */ class Logger { HashMap< ...
- [LeetCode] Logger Rate Limiter 记录速率限制器
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
- LeetCode 359 Logger Rate Limiter
Problem: Design a logger system that receive stream of messages along with its timestamps, each mess ...
- LeetCode Logger Rate Limiter
原题链接在这里:https://leetcode.com/problems/logger-rate-limiter/ 题目: Design a logger system that receive s ...
- Logger Rate Limiter 十秒限时计数器
[抄题]: Design a logger system that receive stream of messages along with its timestamps, each message ...
- Logger Rate Limiter -- LeetCode
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 记录速率限制器
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
- [LC] 359. Logger Rate Limiter
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
随机推荐
- vivo 手机 video 标签无法播放视频解决方案
1. 针对 vivo 手机单独设置 video 标签加上 controls 此时video 可以点击播放,但是有进度条存在. 2. 将 video 隐藏,用一张图片定位在在 video 所在的位置,点 ...
- [SCOI2009]windy数 代码 (对应数位dp入门)
Code1 (DP版) #include<bits/stdc++.h> #define in(i) (i=read()) using namespace std; int read() { ...
- Git本地安装
1 Git简介 Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码 ...
- TCP层shutdown系统调用的实现分析
概述 shutdown系统调用在tcp层会调用两个函数,对于ESTABLISHED状态需要调用tcp_shutdown关闭连接,对于LISTEN和SYN_SENT状态则需要以非阻塞模式调用tcp_di ...
- 如何使用Navicat监控mysql数据库服务器
https://jingyan.baidu.com/article/c33e3f48de5208ea15cbb525.html 打开Navicat 点击[工具]菜单,选择[服务器监控]下的[MyS ...
- AMBARI部署HADOOP集群(3)
1. 安装ambari-server yum -y install ambari-server 2. ambari server 需要一个数据库存储元数据,默认使用的 Postgres 数据库.默认的 ...
- GitHub:Microsoft
ylbtech-GitHub:Microsoft 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 1. https://github.com/microsoft ...
- 爬虫 selenium + phantomjs / chrome
selenium 模块 Web自动化测试工具, 可运行在浏览器,根据指定命令操作浏览器, 必须与第三方浏览器结合使用 安装 sudo pip3 install selenium phantomjs 浏 ...
- php怎样获取当前页面文件名
因开发需要,常需要获取当前php文件的文件名.php获取当前文件名方法很简单,程序代码如下: <?php function php_self(){ $php_self=substr($_SERV ...
- 【巨坑】springmvc 输出json格式数据的几种方式!
最近公司项目需要发布一些数据服务,从设计到实现两天就弄完了,心中窃喜之. 结果临近部署时突然发现..... 服务输出的JSON 数据中 date 类型数据输出格式要么是时间戳,要么是 {&quo ...