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 ...
随机推荐
- 2014-11-9------- 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- 【原创】Android 从一个Activity跳转到另外一个Activity
Android四大组件activity使用,实现两个activity之间的跳转 基本流程:创建两个activity-将其中一个activity中组件作为事件源-通过组件事件的处理借助intent对象实 ...
- 自定义流程gooflow.08 demo在线演示
一.功能简介 gooflow功能清单1.自定义流程绘制2.自定义属性添加3.支持3种步骤类型 普通审批步骤 自动决策步骤 手动决策步骤 4.决策方式(支持js决策,sql语句决策) 5.审批人员参与方 ...
- DB2 WIN7 WIN8在指示的文件系统中找不到数据库目录
前言:win7下一些软件的不正常,跟win7的权限有很大关系. 在win7下安装db2 9.7客户端后,在cmd中运行db2cmd启动clp,输入db2的任何命令都显示:SQL ...
- session与cookie的区别,有哪些不同之处
session与cookie的区别,根据自己的理解总结如下: (1)cookie是一种客户端的状态管理技术,将状态写在 浏览器端,而session是一种服务器端的状态管理技术,将 状态写在web服务器 ...
- iOS:Swift界面实例1, 简单界面
Apple推出了基于Objective-C的新语言Swift. 通过实例, 我们可以很好的感受这门新语言 注意事项: 在XCode6_Beta中, 如果有中文, IDE的自动补全功能就会失效, 所以开 ...
- 简单学C——第六天
指针 指针是c语言中很灵活的一个内容,当然,灵活的都是较难掌握的.不过,只要理解其实质,学习,运用指针还是一件很轻松的事情的. 首先理解,1.什么是指针? 在c语言中,指针也同Int ,doub ...
- linq 多个left join 和 sql union all -> linq union 方法
( from s in Base_SysMenus join r in Base_RoleRights on s.Menu_Id equals r.Menu_Id into temp f ...
- Scut 上线后遇到的问题
1. 上线后的大并发问题: var sem = new Semaphore(_accepts, _accepts); while (true) { sem.WaitOne(); #pragma war ...
- 你的 Docker 应用是安全的吗?
近一年来,Docker 已经逐渐成为 container 界的事实标准,成为技术人员不可或缺的技能之一,就像 Docker 宣称的那样,「Build,Ship,and Run Any App,Anyw ...