362. Design Hit Counter
这个傻逼题。。我没弄明白
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的更多相关文章
- LeetCode 362. Design Hit Counter
原题链接在这里:https://leetcode.com/problems/design-hit-counter/description/ 题目: Design a hit counter which ...
- [LeetCode] 362. Design Hit Counter 设计点击计数器
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- [LC] 362. Design Hit Counter
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- 【LeetCode】362. Design Hit Counter 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode ...
- [LeetCode] Design Hit Counter 设计点击计数器
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- LeetCode Design Hit Counter
原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...
- Design Hit Counter
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- AN ESAY HIT COUNTER
<?php $counts = ("hitcounter.txt"); $hits = file($counts); $hits[0] ++; $fp = fopen($co ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
随机推荐
- 前端开发构建工具gulp的安装使用
曾几何时还在使用grunt作为前端的构建工具,直到有一天同事向我推荐了gulp,在这里博主将不讨论gulp与grunt各自优势的比较,只为大家介绍gulp如何安装和使用. Gulp 是用 nodejs ...
- 《转》前端性能优化----yahoo前端性能团队总结的35条黄金定律
除了自己总结:1. 减少http请求,2.压缩并优化js/css/image 3.尽量静态页面,从简原则 4.代码规范(详见:个人知识体系思维导图) 从yahoo 新学到的: 网页内容 减少http请 ...
- JAVA学习-基础知识
1.Java程序都是以类的形式编写的.2.存放源代码的文件叫源文件.(电脑不能直接看懂的,需要编译一下,电脑才能懂)如何编译源文件?用javac命令输入"javac 123.Java&quo ...
- 线性回顾-generalize issue
Ein的平均,Eout的平均 用这个平均来justify linear regresssion能够用的很好 noise level 资料里有多少的杂讯 等一下要证明的事情 predictions + ...
- Android 6.0 Permission权限与安全机制
Marshmallow版本权限修改 android的权限系统一直是首要的安全概念,因为这些权限只在安装的时候被询问一次.一旦安装了,app可以在用户毫不知晓的情况下访问权限内的所有东西,而且一般用户安 ...
- php中include文件夹分析
include是包含很多php文件的一种汇总:一般放在文件夹最外层. <?php header("content-type:text/html;charset=utf-8") ...
- etTimeout与setInterval方法的区别
etTimeout与setInterval方法的区别 setTimeout()用于设定在指定的时间之后执行对应的函数或代码.,在全局作用域下执行 setTimeout(code,time[,args… ...
- 用Python实现的一个简单的爬取省市乡镇的行政区划信息的脚本
# coding=utf-8 # Creeper import os import bs4 import time import MySQLdb import urllib2 import datet ...
- mybaits不能出现小于号
org.xml.sax.SAXParseException; lineNumber: 146; columnNumber: 54; The content of elements must consi ...
- linux c++ 遍历一个目录下的文件名 (包括子目录的文件名)
最近写代码有一个要遍历目录下的每一个文件并取得这个文件的绝对路径的需求, 我们知道linux c++中有system命令所以我在代码中 先生成了一个log,然后去读log文件的每一行文件名,然后给存储 ...