/*
* 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. leetcode-5-basic

    解题思路: 设两个变量land和sink,land的值是1的数量,sink表示内部的边.result = land*4-sink*2.按行扫描得到land, 同时得到同一行中内部边的数目:然后按列扫描 ...

  2. 虚拟化技术xen,kvm,qemu区别

    虚拟化类型 全虚拟化(Full Virtualization) 全虚拟化也成为原始虚拟化技术,该模型使用虚拟机协调guest操作系统和原始硬件,VMM在guest操作系统和裸硬件之间用于工作协调,一些 ...

  3. 利用委托实现自己的数据缓存仓库(附上Demo)

    Demo源码 写在前面的话 写完这篇博客后,总觉得少了些什么,后来想了下,感觉自己只是把结果给亮了出来,自己为什么想到这么做,这个类库出生的缘由未详述,因此,在本段作下说明,如有不足之处,希望能和大家 ...

  4. quarz spring boot

    package com.pkfare.task.manage.config; import org.quartz.spi.TriggerFiredBundle; import org.springfr ...

  5. day01_05.数学运算符

    数学运算符 $zhang = 100; $lisi = 50; echo $zhang+$lisi; 答案:150 $zhang = 50; $lisi = 40; echo $zhang - $li ...

  6. python递归函数、二分法、匿名函数、(sorted、map、filter内置函数应用)

    #函数递归是一种特殊的函数嵌套调用,在调用一个函数的过程中,又直接或间接的调用该函数本身递归必须要有两个明确的阶段: 递推:一层一层递归调用下去,强调每进入下一层递归问题的规模都必须有所减少 回溯:递 ...

  7. 以前刷过的FFT

    Gym - 101667H 2017-2018 ACM-ICPC, Asia Daejeon Regional Contest #include<bits/stdc++.h> using ...

  8. tomcat(不仅仅是tomcat)通过熵池解决在linux启动应用慢

    tomcat启动过程中报错 -Jul- ::] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web applica ...

  9. 在Ubuntu中,用mvn打包hadoop源代码时报错,正在解决中!!!

    报错信息如下: (各种配置在最后面) hadoop@administrator-virtual-machine:~/Downloads/tar/hadoop-3.0.0-alpha1-src$ mvn ...

  10. NOJ——1669xor的难题(详细的树状数组扩展—异或求和)

    [1669] xor的难题 时间限制: 1000 ms 内存限制: 65535 K 问题描述 最近Alex学长有个问题被困扰了很久,就是有同学给他n个数,然后给你m个查询,然后每个查询给你l和r(左下 ...