/*
* 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的更多相关文章

  1. LeetCode 359 Logger Rate Limiter

    Problem: Design a logger system that receive stream of messages along with its timestamps, each mess ...

  2. LeetCode 359. Logger Rate Limiter (记录速率限制器)$

    Design a logger system that receive stream of messages along with its timestamps, each message shoul ...

  3. [LeetCode] 359. Logger Rate Limiter 记录速率限制器

    Design a logger system that receive stream of messages along with its timestamps, each message shoul ...

  4. [LC] 359. Logger Rate Limiter

    Design a logger system that receive stream of messages along with its timestamps, each message shoul ...

  5. 【LeetCode】359. Logger Rate Limiter 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode ...

  6. [LeetCode] Logger Rate Limiter 记录速率限制器

    Design a logger system that receive stream of messages along with its timestamps, each message shoul ...

  7. LeetCode Logger Rate Limiter

    原题链接在这里:https://leetcode.com/problems/logger-rate-limiter/ 题目: Design a logger system that receive s ...

  8. Logger Rate Limiter 十秒限时计数器

    [抄题]: Design a logger system that receive stream of messages along with its timestamps, each message ...

  9. Logger Rate Limiter -- LeetCode

    Design a logger system that receive stream of messages along with its timestamps, each message shoul ...

随机推荐

  1. HDU 5396 区间DP 数学 Expression

    题意:有n个数字,n-1个运算符,每个运算符的顺序可以任意,因此一共有 (n - 1)! 种运算顺序,得到 (n - 1)! 个运算结果,然后求这些运算结果之和 MOD 1e9+7. 分析: 类比最优 ...

  2. asynctask 异步下载

    public class MainActivity extends Activity{ private TextView show; @Override public void onCreate(Bu ...

  3. 什么是Maven?

    Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 发文时,绝大多数开发人员都把 Ant 当作 Java 编程项目的标准构建工具.遗憾的是, ...

  4. 如何利用App打造自明星实现自盈利

    1.了解各个概念      为了大家都能看懂这篇文章,先说明几个概念.       App(Application):可以在移动设备上使用,满足人们咨询.购物.社交.娱乐.搜索等需求的一切应用程序.  ...

  5. Eclipse常用配置及常用快捷键

    Eclipse常用配置 ① 对编辑窗口视图的字体大小和字体类型进行配置; ②对控制台和xml文本字体大小和字体类型进行设置; ③ 设置.修改eclipse所使用的jdk环境; ④ 设置.修改当前对ja ...

  6. Graham扫描法 --求凸包

    前言: 首先,什么是凸包? 假设平面上有p0~p12共13个点,过某些点作一个多边形,使这个多边形能把所有点都“包”起来.当这个多边形是凸多边形的时候,我们就叫它“凸包”.如下图:  然后,什么是凸包 ...

  7. 【bzoj3939】[Usaco2015 Feb]Cow Hopscotch 动态开点线段树优化dp

    题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a varian ...

  8. kb-01-d<poj3279>--深搜变种,二进制优化;

    poj--3279 题意: 给n*m的矩阵,0 1组成,每次翻转一个格子可以将上下左右的五个节点翻转,求,把所有的格子翻转成0:输出每个个字的翻转次数:最少字数: 做法: 从上到下,第一行翻转的情况确 ...

  9. SOAP UI(ReadyAPI)学习——第一步:资源帖

    SoapUI的参数说明:http://www.soapui.org/Working-with-soapUI/preferences.html 进一步了解可以阅读:http://www.51testin ...

  10. 学习 WebService 第一步:体系结构、三元素SOAP/WSDL/UDDI

    原文地址:爱军的博客——WebService简介 一.为什么需要Web Service 笔记: WebService 可以实现 跨(硬件.服务器.开发工具.平台.应用程序.程序语言……)共享数据和应用 ...