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 ...
随机推荐
- .NET面试题系列(22)字符串暂存池(缓冲池)
序言 字符串不可变性,字符串的‘暂存池’两个特性 字符串是引用类型,程序中会存在大量的字符串对象,如果每次都创建一个字符串对象,会比较浪费内存.性能低,因此CLR做了“暂存池”(拘留池,缓冲池,暂存池 ...
- CF1033D Divisors Pollard-rho
好像卡常,第10个点一直TLE~ Code: #include <bits/stdc++.h> #define ll long long #define ull unsigned long ...
- jQuery动画之停止动画
语法格式: $(selector).stop(true, false); 第一个参数: + ture: 后续动画不执行 false:后续动画会执行 第二个参数: true: 立即执行完成当前动画 fa ...
- python3精品解析运算符
算数运算符 +:两个对象相加 -:得到负数或者,或者一个数减去另一个数 *:两个数相乘或者是返回一个被重复若干次的字符串 /:5/2等于2.1 5//2=2(/有余数,//取整) %:取模(5%2=1 ...
- 关于数据库表设计之区域表system_district:省市县街道四级地址表
关于省市县的数据表的设计有两种方式: 一.将其设计成一张表 DROP TABLE IF EXISTS `system_district`; CREATE TABLE `system_district` ...
- js图片轮播效果实现代码
首先给大家看一看js图片轮播效果,如下图 具体思路: 一.页面加载.获取整个容器.所有放数字索引的li及放图片列表的ul.定义放定时器的变量.存放当前索引的变量index 二.添加定时器,每隔2秒钟i ...
- [nginx]设置代理和静态资源目录
upstream disconf { server ; #tomcat服务器的地址 } server { listen ; #监听端口 server_name localhost; #域名 index ...
- 阶段3 3.SpringMVC·_07.SSM整合案例_06.ssm整合之编写MyBatis框架
需要先搭建Mybits的环境. 用Mybits的注解的方式.把两个方法的sql语句写完 SqlMapConfig.xml resources下新建xml文档 把约束粘贴过来 两步操作 环境标签叫做en ...
- 阶段3 3.SpringMVC·_07.SSM整合案例_03ssm整合之编写Spring框架
做整合要保证每个框架单独使用 先搭建Spring的框架,然后再整合别的框架.Spring是业务层的框架 spring的配置文件 这就表示是spring的配置文件 默认的约束不够,需要修改. <b ...
- JSON+如何处理JSON字符串
JSON(Javascript Object Notation)是一种轻量级的数据交换语言,以文字为基础,且易于让人阅读.尽管JSON是在Javascript的一个子集,但JSON是独立于语言的文本格 ...