当前位置:网站首页>LeetCode 362. Design Hit Counter
LeetCode 362. Design Hit Counter
2022-08-10 11:57:00 【Mizuna pen】
The question is locked,Visit the solution address:https://blog.csdn.net/jmspan/article/details/51738164
hit(timestamp)Pass in a moment,Indicates that a tap was made at that moment;
gethit(timestamp) Pass in a moment,means at that moment5分钟内的敲击次数
使用一个map,Save the time and number of taps.When returning the number of hits,遍历整个map;如果超时了,就删除.只保留5分钟之内的.
int count = 0;
Map<Integer, Integer> map = new HashMap<>();
public void hit(int timestamp) {
count++;
int result = map.getOrDefault(timestamp,0) + 1;
map.put(timestamp, result);
// getHits(timestamp);
}
public int getHits(int timestamp) {
Iterator<Map.Entry<Integer, Integer>> iterator = map.entrySet().iterator();
Map.Entry<Integer, Integer> entry;
while (iterator.hasNext()) {
entry = iterator.next();
if (timestamp-entry.getKey() >= 300) {
iterator.remove();
count-=entry.getValue();
}
}
return count;
}
边栏推荐
- 力扣练习——60 二叉搜索子树的最大键值和
- CPU多级缓存与缓存一致性
- 面试官:你们是如何保证接口的幂等性?
- Not just running away, but saving the guy who mishandled rm -rf /*
- 建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
- LeetCode 61. 旋转链表
- LeetCode50天刷题计划(Day 16—— 两两交换链表中的节点(9.10-10.30)
- LeetCode 25. K 个一组翻转链表
- 中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
猜你喜欢

学长告诉我,大厂MySQL都是通过SSH连接的

推荐6个自媒体领域,轻松易上手

Where can I view the version record of WeChat applet submission review history?

自媒体爆款标题怎么写?手把手教你写热门标题
今天面了个腾讯拿38K出来的大佬,让我见识到了基础的天花板

皕杰报表在传参乱码

Nocalhost - 让云原生时代的开发更高效

Since the media hot style title how to write?Taught you how to write the title

Flutter气泡框实现

电脑怎么设置屏幕息屏时间(日常使用分享)
随机推荐
rider内Mono脚本找不到引用资源
Alibaba最新神作!耗时182天肝出来1015页分布式全栈手册太香了
Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability
Licking Exercise - 59 From Binary Search Trees to Greater Sum Trees
开源的作者,也有个生活问题
Buckle exercise - rectangular area does not exceed the maximum value of K and (hard)
LeetCode_443_压缩字符串
【机器学习】浅谈正规方程法&梯度下降
L2 applications from a product perspective: why is it a playground?
使用JMeter进行MySQL的压力测试
Licking Exercise - 60 Maximum key-value sum of binary search subtrees
LCD驱动端与设备端名称匹配过程分析(Tiny4412)
gpu-admission 源码分析
基于UiAutomator2+PageObject模式开展APP自动化测试实战
再有人问你分布式事务,把这篇扔给他
老板加薪!看我做的WPF Loading!!!
【LeetCode】640. 求解方程
LeetCode 445. 两数相加 II
力扣练习——62 有效的数独
配置druid数据源「建议收藏」