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

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. JavaScript设置右下角悬浮窗

    很多时候,我们需要设置一个dom节点到浏览器窗口的右下角.我们需要那个元素可以在窗口Scroll滚动或者变换大小resize的时候都可以保持浮动在那个位置.这个时候,我在网上看了看,发现很多框架什么啊 ...

  2. Windows phone 之Socket

    服务器端: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...

  3. jQuery源码整体结构(源码2.0.3)

    拨开jQuery的面纱,最近了解了下jQuery源码整体框架.主要包括: (1)  jQuery 核心模块 (2)  sizzle 选择器引擎 (3)  Deferred 异步队列 (4)  Supp ...

  4. InstallShield 创建自己的Dialog

    1.在"User Interface"-"Dialogs"下,在All Dialogs右击"New Dialogs-"创建自己的Dialog ...

  5. ubuntu下openGL的配置方法

    This is a simple tutorial to show a new linux user (such as myself) how to setup freeglut and OpenGl ...

  6. 把一个string串的所有小写字母转成大写字母的例子来看看看全局函数的使用

    今天写了一个小例子,把字符串里面的所有小写字母全部转换成大写字母http://blog.csdn.net/yasaken/article/details/7303903 1 #include &quo ...

  7. HDU 5726 GCD (2016 Multi-University Training Contest 1)

      Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Give y ...

  8. WCF SOAP

    WCF SOAP服务端解析 ASP.NET Core中间件(Middleware)进阶学习实现SOAP 解析. 本篇将介绍实现ASP.NET Core SOAP服务端解析,而不是ASP.NET Cor ...

  9. iOS 图片转NSData-b

    iOS开发中 UIImage可能经常需要转为NSData 上传 传递等等 有两个比较常用的方法 UIImageJPEGRepresentation UIImagePNGRepresentation 第 ...

  10. iOS NSDecimalNumber 货币计算 四舍五入

    今天遇到一个问题 服务器返回货币数据 妈的 用string > floatvalue   不准确 去百度查查 妈的国人分享精神真差  真他妈的自私 一个破壁文章没几个字 还是从国外翻译过来的 全 ...