/*
* 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. PTA 银行排队问题之单队列多窗口加VIP服务 队列+模拟

    假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙.当有窗口空闲时,下一位顾客即去该窗口处理事务.当有多个窗口可选择时,假设顾客总是选择编号最小的窗口. 有些银行会给 ...

  2. 【原创】关于高版本poi autoSizeColumn方法异常的情况

    之前使用的3.9版本,autoSizeColumn方法一切正常,现在切换到了3.15版本这个方法就出先了问题,问题如下,无法自动追踪所有的列. Exception in thread "ma ...

  3. VMware-Ubuntu入门(1)

    大家都说Linux系统是让程序员用起来更有成就感的系统,我也来体验下: 对于小白鼠的我,并没有直接在电脑上重装Linux系统,而是通过VMware工具搭建Ubuntu虚拟linux环境. 首先展示下V ...

  4. html5/css3常考面试题

    一.HTML5 CSS3 CSS3有哪些新特性? 1. CSS3实现圆角(border-radius),阴影(box-shadow), 2. 对文字加特效(text-shadow.),线性渐变(gra ...

  5. 缓存淘汰算法之LFU

    1. LFU类 1.1. LFU 1.1.1. 原理 LFU(Least Frequently Used)算法根据数据的历史访问频率来淘汰数据,其核心思想是“如果数据过去被访问多次,那么将来被访问的频 ...

  6. python装饰器实现用户密码认证(简单初形)

    import timecurrent_user={'user':None}def auth(engine = 'file'): def deco(func): #func=最初始的index和最初始的 ...

  7. [uiautomator篇] [4] 运行成功的日志打印---最后写一个脚本来实现

    Testing started at 18:23 ... 05/10 18:23:01: Launching ChangeTextBehaviorTestNo apk changes detected ...

  8. Tomcat自动发布war包

    有两种方法: 1.将项目打成war包,复制到${tomcat.home}\webapps目录下.当tomcat启动时会自动将其解包. 有人说,不能直接将war文件夹直接复制到${tomcat.home ...

  9. Android中当前墙纸Wallpaper存放的位置

    最近想做个应用保存当前墙纸,找了一下,发现当前墙纸的位置在. /System/users/0/wallpaper 没有后缀.导出来修改一下名字就可以看到图标了.比如改为png. 但是,这个目录要求系统 ...

  10. HDU——1393Weird Clock(水题,注意题意)

    Weird Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...