359. Logger Rate Limiter
/*
* 359. Logger Rate Limiter
* 2016-7-14 by Mingyang
* 很简单的HashMap,不详谈
*/
class Logger {
HashMap<String, Integer> map;
/** Initialize your data structure here. */
public Logger() {
map = new HashMap<String, Integer>();
}
/**
* 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)) {
map.put(message, timestamp);
return true;
} else {
int temp = map.get(message);
if (timestamp - temp < 10) {
return false;
} else {
map.put(message, timestamp);
return true;
}
}
}
}
359. Logger Rate Limiter的更多相关文章
- 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 ...
- [LC] 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 ...
- [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 十秒限时计数器
[抄题]: 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 ...
随机推荐
- Linux学习-编译前的任务:认识核心与取得核心原始码
什么是核心 (Kernel) Kernel 其实核心就是系统上面的一个文件而已, 这个文件包含了驱动主机各项硬 件的侦测程序与驱动模块. 核心文件通常被放置成 /boot/vmlinuz-xxx ,不 ...
- Hadoop4.2HDFS测试报告之五
第二组:文件存储读过程记录 NameNode:1 DataNode:1 本地存储 scp romotepath localpath 500 2 1 23.05 NameNode:1 DataNode: ...
- Python虚拟机框架
Python字节码 我们知道,Python源代码在执行前,会先将源代码编译为字节码序列,Python虚拟机就根据这些字节码进行一系列的操作,从而完成对Python程序的执行.在Python2.5中,一 ...
- day03_08 变量的重新赋值02
python自动回收垃圾内存,不用了自动会回收,但是C不会 以下del代码为手动强拆,就是从内存中删除变量名
- 零基础学习 Python 之数字与运算
写在之前 大家好,这里是零基础学习 Python 系列,在这里我将从最基本的 Python 写起,然后再慢慢涉及到高阶以及具体应用方面.我是完全自学的 Python,所以很是明白自学对于一个人的考验, ...
- 【转载】logistic回归
原文地址:https://www.cnblogs.com/zichun-zeng/p/3824745.html 1. logistic回归与一般线性回归模型的区别: (1) 线性回归的结果变量 ...
- CM10 WIFI连不上解决方案
手机是Moto Mileston2 ,好久之前就刷成了CM10, 但是一直没出问题. 最近,发现在某些路由器上连接不上,总是 在验证账户或者获取IP. 解决办法如下: http://moto.zol. ...
- [错误解决]UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
python2内容无法写入csv,报错:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordin ...
- [整理]tar压缩下来为什么格式是.tar.gz
前段时间打包,直接用tar命令压缩,压缩好的文件取名rar.同事用winrar打开发现一直报错. 经过查询发现,tar -cvzf压缩下来的格式其实应该是.tar.gz 但是格式怎么会这么奇怪呢?是压 ...
- PTA 11-散列1 电话聊天狂人 (25分)
题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/722 5-14 电话聊天狂人 (25分) 给定大量手机用户通话记录,找出其中通话次数 ...