这个傻逼题。。我没弄明白

you may assume that calls are being made to the system in chronological order (ie, the timestamp is monotonically increasing)

这句话的意思,以为只是盖戳的时间是这样,getHits可以是任意值,我用TEST CASE测试了一下,答案的结果是这样。

比如300S之后,getHits(4)还是能得到正确解,结果卡了好久。

看了答案,发现似乎getHits的parameter只会比当前时间要晚。。。我真是要报警了。

public class HitCounter {

        int[] hits;
int[] times;
/** Initialize your data structure here. */
public HitCounter()
{
hits = new int[300];
times = new int[300];
} /** Record a hit.
@param timestamp - The current timestamp (in seconds granularity). */
public void hit(int timestamp)
{
if(times[timestamp%300] == timestamp)
{
hits[timestamp%300]++;
}
else
{
hits[timestamp%300] = 1;
times[timestamp%300] = timestamp;
}
} /** Return the number of hits in the past 5 minutes.
@param timestamp - The current timestamp (in seconds granularity). */
public int getHits(int timestamp)
{
int res = 0;
for(int i = 0; i < 300;i++)
{
if(timestamp - times[i] < 300) res += hits[i];
} return res;
}
}

我这个智商没救了,别刷题了,去吃屎好了。

362. Design Hit Counter的更多相关文章

  1. LeetCode 362. Design Hit Counter

    原题链接在这里:https://leetcode.com/problems/design-hit-counter/description/ 题目: Design a hit counter which ...

  2. [LeetCode] 362. Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  3. [LC] 362. Design Hit Counter

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  4. 【LeetCode】362. Design Hit Counter 解题报告 (C++)

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

  5. [LeetCode] Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  6. LeetCode Design Hit Counter

    原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...

  7. Design Hit Counter

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  8. AN ESAY HIT COUNTER

    <?php $counts = ("hitcounter.txt"); $hits = file($counts); $hits[0] ++; $fp = fopen($co ...

  9. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

随机推荐

  1. HDU 3006 The Number of set(位运算 状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3006 题目大意:给定n个集合,每个集合都是由大于等于1小于等于m的数字组成,m最大为14.由给出的集合 ...

  2. VMware虚拟机中如何安装VMWare-Tools详解

    VMware虚拟机中如何安装VMWare-Tools详解 好处:可以支持图形界面,可以支持共享文件功能等 VMware虚拟机中如何配置显 VMware作为一款虚拟机利器,很多人都利用它来实现Linux ...

  3. PHP 单一入口

    单一入口概述 单一入口的应用程序就是说用一个文件处理所有的HTTP请求,例如不管是列表页还是文章页,都是从浏览器访问index.php文件,这个文件就是这个应用程序的单一入口. 打个比方,大家都要上W ...

  4. angularjs跨域调取webservice

    1.配置 web.config <webServices> <!--必须添加--> <protocols> <add name="HttpGet&q ...

  5. Windows phone 之Xml操作

    最近在做天气预报应用,这个应用中需要用到Xml来存储关注的城市列表,保存一下代码,方便以后使用,也给博友们一个参考: 其中:添加关注城市的操作代码是: 其实就是, (1)先把数据从CareCityCo ...

  6. 配置处理结果result

    Action处理完用户请求后返回一个字符串,整个字符串就是一个逻辑视图名. 除此之外,struts2还支持多种结果映射,struts2将结果转为实际资源时,不仅可以是JSP视图资源,也可以是FreeM ...

  7. JS判断浏览器类型以及版本号

    <script type="text/javascript">        (function(){            window.nav={};       ...

  8. [转载]为什么使用%lf读取double型的值,而用%f进行显示?

    博客地址:http://blog.csdn.net/shenzhou111/article/details/7826444 今天看到一篇好文章,mark一下. 出去旅游了一下,所以有些天没敲代码,于是 ...

  9. 10055 - Hashmat the Brave Warrior

    Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...

  10. 线性表之顺序存储结构(C语言动态数组实现)

    线性表的定义:N个数据元素的有限序列 线性表从存储结构上分为:顺序存储结构(数组)和 链式存储结构(链表) 顺序存储结构:是用一段连续的内存空间存储表中的数据 L=(a1,a2,a3....an) 链 ...